Class: JA2R::Element
- Inherits:
-
Object
- Object
- JA2R::Element
- Defined in:
- lib/ja2r/element.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#relationships ⇒ Object
readonly
Returns the value of attribute relationships.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #attribute(key) ⇒ Object
-
#initialize(payload) ⇒ Element
constructor
A new instance of Element.
- #meta(key) ⇒ Object
Constructor Details
#initialize(payload) ⇒ Element
Returns a new instance of Element.
3 4 5 6 7 8 9 |
# File 'lib/ja2r/element.rb', line 3 def initialize(payload) @id = payload['id'] @type = payload['type'] @attributes = (payload['attributes'] || {}).with_indifferent_access @meta = (payload['meta'] || {}).with_indifferent_access @relationships = payload['relationships'] ? convert_relationship(payload['relationships']) : {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (private)
23 24 25 26 27 28 |
# File 'lib/ja2r/element.rb', line 23 def method_missing(method, *args) return attributes[method] if attributes&.key? method return relationships[method] if relationships&.key? method super end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
11 12 13 |
# File 'lib/ja2r/element.rb', line 11 def attributes @attributes end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/ja2r/element.rb', line 11 def id @id end |
#relationships ⇒ Object (readonly)
Returns the value of attribute relationships.
11 12 13 |
# File 'lib/ja2r/element.rb', line 11 def relationships @relationships end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/ja2r/element.rb', line 11 def type @type end |
Instance Method Details
#attribute(key) ⇒ Object
13 14 15 |
# File 'lib/ja2r/element.rb', line 13 def attribute(key) @attributes[key] end |
#meta(key) ⇒ Object
17 18 19 |
# File 'lib/ja2r/element.rb', line 17 def (key) @meta[key] end |