Class: HashSerializer::Attribute
- Inherits:
-
Object
- Object
- HashSerializer::Attribute
- Defined in:
- lib/hash_serializer/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #as_json(object) ⇒ Object
-
#initialize(name, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #key_name ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
5 6 7 8 |
# File 'lib/hash_serializer/attribute.rb', line 5 def initialize(name, = {}) @name = name @options = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/hash_serializer/attribute.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/hash_serializer/attribute.rb', line 3 def @options end |
Instance Method Details
#as_json(object) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/hash_serializer/attribute.rb', line 14 def as_json(object) value = object.public_send(name) case [:format] when Symbol value = object.formats[[:format]].call(value) end { key_name => value } end |
#key_name ⇒ Object
10 11 12 |
# File 'lib/hash_serializer/attribute.rb', line 10 def key_name [:as] || name end |