class Necromancer::Converter

Abstract converter used internally as a base for other converters

@api private

Attributes

config[R]
convert[RW]
source[RW]
target[RW]

Public Class Methods

create(&block) click to toggle source

Creates anonymous converter

@api private

# File lib/necromancer/converter.rb, line 34
def self.create(&block)
  Class.new(self) do
    define_method(:initialize) { |*a| block.call(self, *a) }

    define_method(:call) { |value| convert.call(value) }
  end.new
end
new(source = nil, target = nil) click to toggle source

Create an abstract converter

@param [Object] source

the source object type

@param [Object] target

the target object type

@api public

# File lib/necromancer/converter.rb, line 18
def initialize(source = nil, target = nil)
  @source = source if source
  @target = target if target
  @config ||= Configuration.new
end

Public Instance Methods

call(*) click to toggle source

Run converter

@api private

# File lib/necromancer/converter.rb, line 27
def call(*)
  fail NotImplementedError
end
fail_conversion_type(value) click to toggle source

Fail with conversion type error

@param [Object] value

the value that cannot be converted

@api private

# File lib/necromancer/converter.rb, line 48
def fail_conversion_type(value)
  fail ConversionTypeError, "'#{value}' could not be converted " \
                            "from `#{source}` into `#{target}` "
end