Class: JA2R::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/ja2r/element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject (readonly)

Returns the value of attribute attributes.



11
12
13
# File 'lib/ja2r/element.rb', line 11

def attributes
  @attributes
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/ja2r/element.rb', line 11

def id
  @id
end

#relationshipsObject (readonly)

Returns the value of attribute relationships.



11
12
13
# File 'lib/ja2r/element.rb', line 11

def relationships
  @relationships
end

#typeObject (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 meta(key)
  @meta[key]
end