Module: Omnis::Transformer::InstanceMethods
- Defined in:
- lib/omnis/transformer.rb
Instance Method Summary collapse
- #columns ⇒ Object
- #property_value(property, source) ⇒ Object
-
#to_proc ⇒ Object
provides a Proc to the transform method, for use e.g.
- #transform(source) ⇒ Object
Instance Method Details
#columns ⇒ Object
68 69 70 |
# File 'lib/omnis/transformer.rb', line 68 def columns self.class.properties.keys end |
#property_value(property, source) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/omnis/transformer.rb', line 72 def property_value(property, source) raw_value = property.extract(source) raw_value = property.default if property.default && (raw_value == Nothing || raw_value.nil?) applied_value = self.class.apply_to_value(raw_value) property.format ? property.format.call(applied_value) : applied_value end |
#to_proc ⇒ Object
provides a Proc to the transform method, for use e.g. with Mongo documents If you want to cache a transformer for reuse, you can cache just this Proc
86 87 88 |
# File 'lib/omnis/transformer.rb', line 86 def to_proc method(:transform).to_proc end |
#transform(source) ⇒ Object
79 80 81 82 |
# File 'lib/omnis/transformer.rb', line 79 def transform(source) result = Hash[self.class.properties.map do |k, v| [k, property_value(v, source)] end] respond_to?(:to_object) ? to_object(result) : result end |