Class: JA2R::Element
- Inherits:
-
Object
show all
- Defined in:
- lib/ja2r/element.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(origin_data, options = {}) ⇒ Element
3
4
5
6
7
8
|
# File 'lib/ja2r/element.rb', line 3
def initialize(origin_data, options = {})
@origin_data = origin_data.with_indifferent_access
@options = options
@relationships = origin_data['relationships']&.then { |rd| convert_relationships(rd) } || {}
build_references
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/ja2r/element.rb', line 55
def method_missing(symbol, *args)
case @references[symbol]
in attribute:
attributes[attribute]
in relationship:
relationships[relationship]
else
safe_traverse? ? nil : super
end
end
|
Instance Attribute Details
#origin_data ⇒ Object
Also known as:
serializable_hash
Returns the value of attribute origin_data.
10
11
12
|
# File 'lib/ja2r/element.rb', line 10
def origin_data
@origin_data
end
|
#relationships ⇒ Object
Returns the value of attribute relationships.
10
11
12
|
# File 'lib/ja2r/element.rb', line 10
def relationships
@relationships
end
|
Instance Method Details
#attribute(key) ⇒ Object
12
13
14
|
# File 'lib/ja2r/element.rb', line 12
def attribute(key)
origin_data.dig 'attributes', key
end
|
#attributes ⇒ Object
16
17
18
|
# File 'lib/ja2r/element.rb', line 16
def attributes
origin_data['attributes']
end
|
#id ⇒ Object
20
21
22
|
# File 'lib/ja2r/element.rb', line 20
def id
origin_data['id']
end
|
#link(key) ⇒ Object
24
25
26
|
# File 'lib/ja2r/element.rb', line 24
def link(key)
origin_data.dig 'links', key
end
|
28
29
30
|
# File 'lib/ja2r/element.rb', line 28
def meta(key)
origin_data.dig 'meta', key
end
|
#type ⇒ Object
37
38
39
|
# File 'lib/ja2r/element.rb', line 37
def type
origin_data['type']
end
|