Class: Necromancer::Converter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/necromancer/converter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Abstract converter used internally as a base for other converters

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source = nil, target = nil) ⇒ Converter

Create an abstract converter

Parameters:

  • source (Object) (defaults to: nil)

    the source object type

  • target (Object) (defaults to: nil)

    the target object type



19
20
21
22
23
# 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

Instance Attribute Details

#configObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

protected



62
63
64
# File 'lib/necromancer/converter.rb', line 62

def config
  @config
end

#convertObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
# File 'lib/necromancer/converter.rb', line 58

def convert
  @convert
end

#sourceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/necromancer/converter.rb', line 54

def source
  @source
end

#targetObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
# File 'lib/necromancer/converter.rb', line 56

def target
  @target
end

Class Method Details

.create(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates anonymous converter



35
36
37
38
39
40
41
# 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

Instance Method Details

#callObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run converter

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/necromancer/converter.rb', line 28

def call(*)
  raise NotImplementedError
end

#raise_conversion_type(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Fail with conversion type error

Parameters:

  • value (Object)

    the value that cannot be converted

Raises:



49
50
51
52
# File 'lib/necromancer/converter.rb', line 49

def raise_conversion_type(value)
  raise ConversionTypeError, "'#{value}' could not be converted " \
                             "from `#{source}` into `#{target}`"
end