Class: O::Serializer
- Inherits:
-
Object
- Object
- O::Serializer
- Extended by:
- ArefShortcut
- Defined in:
- lib/o/serializer.rb,
lib/o/serializer/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
- #call(object) ⇒ Object
-
#initialize(fields) ⇒ Serializer
constructor
A new instance of Serializer.
Methods included from ArefShortcut
Constructor Details
#initialize(fields) ⇒ Serializer
Returns a new instance of Serializer.
19 20 21 |
# File 'lib/o/serializer.rb', line 19 def initialize(fields) @fields = fields end |
Instance Method Details
#call(object) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/o/serializer.rb', line 23 def call(object) return nil if object.nil? @fields .map { |key, field| [key, field.call(object)] } .to_h end |