Class: Estratto::Data::Coercer
- Inherits:
-
Object
- Object
- Estratto::Data::Coercer
- Defined in:
- lib/estratto/data/coercer.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(data:, type: 'String', formats: {}) ⇒ Coercer
constructor
A new instance of Coercer.
- #target_coercer ⇒ Object
Constructor Details
#initialize(data:, type: 'String', formats: {}) ⇒ Coercer
Returns a new instance of Coercer.
14 15 16 17 18 |
# File 'lib/estratto/data/coercer.rb', line 14 def initialize(data:, type: 'String', formats: {}) @data = data @type = type @formats = formats end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
12 13 14 |
# File 'lib/estratto/data/coercer.rb', line 12 def data @data end |
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
12 13 14 |
# File 'lib/estratto/data/coercer.rb', line 12 def formats @formats end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/estratto/data/coercer.rb', line 12 def type @type end |
Instance Method Details
#build ⇒ Object
20 21 22 |
# File 'lib/estratto/data/coercer.rb', line 20 def build target_coercer.coerce end |
#target_coercer ⇒ Object
24 25 26 27 28 |
# File 'lib/estratto/data/coercer.rb', line 24 def target_coercer Object.const_get("Estratto::Data::#{type}").new(data, formats) rescue NameError raise InvalidCoercionType end |