Class: Terrestrial::Serializer
- Inherits:
-
Object
- Object
- Terrestrial::Serializer
- Defined in:
- lib/terrestrial/serializer.rb
Instance Attribute Summary collapse
-
#field_names ⇒ Object
readonly
Returns the value of attribute field_names.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#initialize(field_names, object) ⇒ Serializer
constructor
A new instance of Serializer.
- #to_h ⇒ Object
Constructor Details
#initialize(field_names, object) ⇒ Serializer
Returns a new instance of Serializer.
3 4 5 6 |
# File 'lib/terrestrial/serializer.rb', line 3 def initialize(field_names, object) @field_names = field_names @object = object end |
Instance Attribute Details
#field_names ⇒ Object (readonly)
Returns the value of attribute field_names.
8 9 10 |
# File 'lib/terrestrial/serializer.rb', line 8 def field_names @field_names end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
8 9 10 |
# File 'lib/terrestrial/serializer.rb', line 8 def object @object end |
Instance Method Details
#to_h ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/terrestrial/serializer.rb', line 10 def to_h Hash[ field_names.map { |field_name| [field_name, object.public_send(field_name)] } ] end |