Module: Omnis::Transformer::InstanceMethods
- Defined in:
- lib/omnis/transformer.rb
Instance Method Summary collapse
- #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
#property_value(property, source) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/omnis/transformer.rb', line 68 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
82 83 84 |
# File 'lib/omnis/transformer.rb', line 82 def to_proc method(:transform).to_proc end |
#transform(source) ⇒ Object
75 76 77 78 |
# File 'lib/omnis/transformer.rb', line 75 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 |