class Estratto::Data::Coercer
Attributes
data[R]
formats[R]
index[R]
type[R]
Public Class Methods
new(data:, index:, type: 'String', formats: {})
click to toggle source
# File lib/estratto/data/coercer.rb, line 14 def initialize(data:, index:, type: 'String', formats: {}) @data = data @index = index @type = type @formats = formats end
Public Instance Methods
allow_empty?()
click to toggle source
# File lib/estratto/data/coercer.rb, line 36 def allow_empty? formats.dig('allow_empty') end
build()
click to toggle source
# File lib/estratto/data/coercer.rb, line 21 def build target_coercer.coerce rescue StandardError => error unless allow_empty? raise DataCoercionError, "Error when coercing #{data} on line #{index}, raising: #{error.message}" end end
target_coercer()
click to toggle source
# File lib/estratto/data/coercer.rb, line 30 def target_coercer Object.const_get("Estratto::Data::#{type}").new(data, formats) rescue NameError raise InvalidCoercionType, "Does not exists coercer class for #{type}" end