Class: Estratto::Data::Coercer

Inherits:
Object
  • Object
show all
Defined in:
lib/estratto/data/coercer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



12
13
14
# File 'lib/estratto/data/coercer.rb', line 12

def data
  @data
end

#formatsObject (readonly)

Returns the value of attribute formats.



12
13
14
# File 'lib/estratto/data/coercer.rb', line 12

def formats
  @formats
end

#typeObject (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

#buildObject



20
21
22
# File 'lib/estratto/data/coercer.rb', line 20

def build
  target_coercer.coerce
end

#target_coercerObject



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