Class: Jacoat::Document::Relationship

Inherits:
Object
  • Object
show all
Defined in:
lib/jacoat/document/relationship.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/jacoat/document/relationship.rb', line 4

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/jacoat/document/relationship.rb', line 4

def id
  @id
end

Returns the value of attribute links.



4
5
6
# File 'lib/jacoat/document/relationship.rb', line 4

def links
  @links
end

#typeObject (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_hashObject



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