Class: Jacoat::Document::ResourceIdentifier
- Inherits:
-
Object
- Object
- Jacoat::Document::ResourceIdentifier
- Defined in:
- lib/jacoat/document/resource_identifier.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#relationships ⇒ Object
readonly
Returns the value of attribute relationships.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #create_relationships(hash) ⇒ Object
-
#initialize(arguments) ⇒ ResourceIdentifier
constructor
A new instance of ResourceIdentifier.
- #relationship_hash ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(arguments) ⇒ ResourceIdentifier
Returns a new instance of ResourceIdentifier.
17 18 19 20 21 |
# File 'lib/jacoat/document/resource_identifier.rb', line 17 def initialize(arguments) @id = arguments[:id] @type = arguments[:type] create_relationships(arguments[:relationships]) if arguments.has_key?(:relationships) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/jacoat/document/resource_identifier.rb', line 4 def id @id end |
#relationships ⇒ Object (readonly)
Returns the value of attribute relationships.
4 5 6 |
# File 'lib/jacoat/document/resource_identifier.rb', line 4 def relationships @relationships end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/jacoat/document/resource_identifier.rb', line 4 def type @type end |
Class Method Details
.process(body) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/jacoat/document/resource_identifier.rb', line 5 def self.process(body) if body.is_a?(Array) resources = [] body.each do |item| resources << ResourceIdentifier.new(item) end else resources = ResourceIdentifier.new(body) end resources end |
Instance Method Details
#create_relationships(hash) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/jacoat/document/resource_identifier.rb', line 23 def create_relationships(hash) @relationships = [] hash.each_pair do |k, v| @relationships << Document::Relationship.new(k, v) end end |
#relationship_hash ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/jacoat/document/resource_identifier.rb', line 39 def relationship_hash hash = {} @relationships.each do |relationship| hash.merge!(relationship.to_hash) end hash end |
#to_hash ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/jacoat/document/resource_identifier.rb', line 30 def to_hash hash = { type: @type, id: @id } hash.merge!(relationships: relationship_hash) if @relationships hash end |