Class: Jacoat::Document::Relationship
- Inherits:
-
Object
- Object
- Jacoat::Document::Relationship
- Defined in:
- lib/jacoat/document/relationship.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#id ⇒ Object
Returns the value of attribute id.
-
#links ⇒ Object
Returns the value of attribute links.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type) ⇒ Relationship
constructor
A new instance of Relationship.
- #process_jsonapi(hash) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(type) ⇒ Relationship
Returns a new instance of Relationship.
15 16 17 |
# File 'lib/jacoat/document/relationship.rb', line 15 def initialize(type) @type = type.to_s end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/jacoat/document/relationship.rb', line 4 def data @data end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/jacoat/document/relationship.rb', line 4 def id @id end |
#links ⇒ Object
Returns the value of attribute links.
4 5 6 |
# File 'lib/jacoat/document/relationship.rb', line 4 def links @links end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/jacoat/document/relationship.rb', line 4 def type @type end |
Class Method Details
.from_jsonapi(hash) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/jacoat/document/relationship.rb', line 5 def self.from_jsonapi(hash) relationships = [] hash.each_pair do |k, v| relationship = Document::Relationship.new(k) relationship.process_jsonapi(v) relationships << relationship end relationships end |
Instance Method Details
#process_jsonapi(hash) ⇒ Object
27 28 29 30 31 |
# File 'lib/jacoat/document/relationship.rb', line 27 def process_jsonapi(hash) process_data(hash[:data]) if hash.has_key?(:data) process_body(hash[:links]) if hash.has_key?(:links) self end |
#to_hash ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/jacoat/document/relationship.rb', line 19 def to_hash hash = {} hash[type.to_sym] = {} hash[type.to_sym].merge!(links: @links.to_hash) if @links hash[type.to_sym].merge!(data: data_to_hash) if @data hash end |