Class: Necromancer::Converter Private
- Inherits:
-
Object
- Object
- Necromancer::Converter
- 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
Direct Known Subclasses
ArrayConverters::ArrayToBooleanArrayConverter, ArrayConverters::ArrayToFloatArrayConverter, ArrayConverters::ArrayToIntegerArrayConverter, ArrayConverters::ArrayToNumericArrayConverter, ArrayConverters::ArrayToSetConverter, ArrayConverters::ObjectToArrayConverter, ArrayConverters::StringToArrayConverter, ArrayConverters::StringToBooleanArrayConverter, ArrayConverters::StringToFloatArrayConverter, ArrayConverters::StringToIntegerArrayConverter, ArrayConverters::StringToNumericArrayConverter, BooleanConverters::BooleanToIntegerConverter, BooleanConverters::IntegerToBooleanConverter, BooleanConverters::StringToBooleanConverter, DateTimeConverters::StringToDateConverter, DateTimeConverters::StringToDateTimeConverter, DateTimeConverters::StringToTimeConverter, HashConverters::StringToBooleanHashConverter, HashConverters::StringToFloatHashConverter, HashConverters::StringToHashConverter, HashConverters::StringToIntegerHashConverter, HashConverters::StringToNumericHashConverter, NullConverter, NumericConverters::IntegerToStringConverter, NumericConverters::StringToFloatConverter, NumericConverters::StringToIntegerConverter, NumericConverters::StringToNumericConverter, RangeConverters::StringToRangeConverter
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
private
protected.
- #convert ⇒ Object private
- #source ⇒ Object private
- #target ⇒ Object private
Class Method Summary collapse
-
.create(&block) ⇒ Object
private
Creates anonymous converter.
Instance Method Summary collapse
-
#call ⇒ Object
private
Run converter.
-
#initialize(source = nil, target = nil) ⇒ Converter
constructor
Create an abstract converter.
-
#raise_conversion_type(value) ⇒ Object
private
Fail with conversion type error.
Constructor Details
#initialize(source = nil, target = nil) ⇒ Converter
Create an abstract converter
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
#config ⇒ Object (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 |
#convert ⇒ 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.
58 59 60 |
# File 'lib/necromancer/converter.rb', line 58 def convert @convert end |
#source ⇒ 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.
54 55 56 |
# File 'lib/necromancer/converter.rb', line 54 def source @source end |
#target ⇒ 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.
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
#call ⇒ 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.
Run converter
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
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 |