Class: Jacoat::Document::Relationship
- Inherits:
-
Object
- Object
- Jacoat::Document::Relationship
- Defined in:
- lib/jacoat/document/relationship.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type, body) ⇒ Relationship
constructor
A new instance of Relationship.
- #to_hash ⇒ Object
Constructor Details
#initialize(type, body) ⇒ Relationship
Returns a new instance of Relationship.
13 14 15 16 17 |
# File 'lib/jacoat/document/relationship.rb', line 13 def initialize(type, body) @type = type.to_s process_data(body[:data]) if body.has_key?(:data) process_body(body[:links]) if body.has_key?(:links) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/jacoat/document/relationship.rb', line 4 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/jacoat/document/relationship.rb', line 4 def id @id end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
4 5 6 |
# File 'lib/jacoat/document/relationship.rb', line 4 def links @links end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/jacoat/document/relationship.rb', line 4 def type @type end |
Class Method Details
.process(hash) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/jacoat/document/relationship.rb', line 5 def self.process(hash) relationships = [] hash.each_pair do |k, v| relationships << Document::Relationship.new(k, v) end relationships end |
Instance Method Details
#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 |