Class: CDMBL::FieldTransformer
- Inherits:
-
Object
- Object
- CDMBL::FieldTransformer
- Defined in:
- lib/cdmbl/field_transformer.rb
Instance Attribute Summary collapse
-
#dest_path ⇒ Object
readonly
Returns the value of attribute dest_path.
-
#field_value ⇒ Object
readonly
Returns the value of attribute field_value.
-
#formatter_klass ⇒ Object
readonly
Returns the value of attribute formatter_klass.
-
#formatters ⇒ Object
readonly
Returns the value of attribute formatters.
Instance Method Summary collapse
-
#initialize(origin_path: '', dest_path: '', record: {}, formatters: [], formatter_klass: FieldFormatter) ⇒ FieldTransformer
constructor
A new instance of FieldTransformer.
- #reduce ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(origin_path: '', dest_path: '', record: {}, formatters: [], formatter_klass: FieldFormatter) ⇒ FieldTransformer
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/cdmbl/field_transformer.rb', line 6 def initialize(origin_path: '', dest_path: '', record: {}, formatters: [], formatter_klass: FieldFormatter) @field_value = compact(record.at_path(origin_path)) @dest_path = dest_path @formatters = (!formatters.nil?) ? formatters : [DefaultFormatter] @formatter_klass = formatter_klass end |
Instance Attribute Details
#dest_path ⇒ Object (readonly)
Returns the value of attribute dest_path.
5 6 7 |
# File 'lib/cdmbl/field_transformer.rb', line 5 def dest_path @dest_path end |
#field_value ⇒ Object (readonly)
Returns the value of attribute field_value.
5 6 7 |
# File 'lib/cdmbl/field_transformer.rb', line 5 def field_value @field_value end |
#formatter_klass ⇒ Object (readonly)
Returns the value of attribute formatter_klass.
5 6 7 |
# File 'lib/cdmbl/field_transformer.rb', line 5 def formatter_klass @formatter_klass end |
#formatters ⇒ Object (readonly)
Returns the value of attribute formatters.
5 6 7 |
# File 'lib/cdmbl/field_transformer.rb', line 5 def formatters @formatters end |
Instance Method Details
#reduce ⇒ Object
17 18 19 |
# File 'lib/cdmbl/field_transformer.rb', line 17 def reduce (blank?(value)) ? {} : { "#{dest_path}" => value } end |
#value ⇒ Object
21 22 23 |
# File 'lib/cdmbl/field_transformer.rb', line 21 def value @value ||= (!blank?(field_value)) ? transform_field : nil end |