class Necromancer::Converter

Abstract converter used internally as a base for other converters

@api private

Attributes

config[R]

protected

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 35
def self.create(&block)
  Class.new(self) do
    define_method(:initialize) { |*a| block.(self, *a) }

    define_method(:call) { |value| convert.(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 19
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 28
def call(*)
  raise NotImplementedError
end
raise_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 49
def raise_conversion_type(value)
  raise ConversionTypeError, "'#{value}' could not be converted " \
                             "from `#{source}` into `#{target}`"
end