Class: HALPresenter::CurieCollection::CurieWithReferences
- Inherits:
-
Object
- Object
- HALPresenter::CurieCollection::CurieWithReferences
- Defined in:
- lib/hal_presenter/curie_collection.rb
Instance Attribute Summary collapse
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
-
#rels ⇒ Object
readonly
Returns the value of attribute rels.
-
#templated ⇒ Object
readonly
Returns the value of attribute templated.
Instance Method Summary collapse
- #<<(other) ⇒ Object
- #add_reference(rel, reference, type) ⇒ Object
-
#initialize(curie) ⇒ CurieWithReferences
constructor
A new instance of CurieWithReferences.
- #rename(name) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(curie) ⇒ CurieWithReferences
Returns a new instance of CurieWithReferences.
8 9 10 11 12 13 14 15 16 |
# File 'lib/hal_presenter/curie_collection.rb', line 8 def initialize(curie) @name = curie.fetch(:name) @href = curie.fetch(:href) @templated = curie.fetch(:templated, true) @rels = Hash.new { |hash, key| hash[key] = Set.new } @references = Hash.new do |hash, key| hash[key] = Set.new.compare_by_identity end end |
Instance Attribute Details
#href ⇒ Object (readonly)
Returns the value of attribute href.
6 7 8 |
# File 'lib/hal_presenter/curie_collection.rb', line 6 def href @href end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/hal_presenter/curie_collection.rb', line 6 def name @name end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
6 7 8 |
# File 'lib/hal_presenter/curie_collection.rb', line 6 def references @references end |
#rels ⇒ Object (readonly)
Returns the value of attribute rels.
6 7 8 |
# File 'lib/hal_presenter/curie_collection.rb', line 6 def rels @rels end |
#templated ⇒ Object (readonly)
Returns the value of attribute templated.
6 7 8 |
# File 'lib/hal_presenter/curie_collection.rb', line 6 def templated @templated end |
Instance Method Details
#<<(other) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/hal_presenter/curie_collection.rb', line 23 def <<(other) other.rels.each do |type, rels| self.rels[type] += rels end other.references.each do |type, references| self.references[type] += references end end |
#add_reference(rel, reference, type) ⇒ Object
18 19 20 21 |
# File 'lib/hal_presenter/curie_collection.rb', line 18 def add_reference(rel, reference, type) rels[type] << rel references[type] << reference end |
#rename(name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hal_presenter/curie_collection.rb', line 32 def rename(name) self.name = name rels.each do |type, rels| rels.each do |rel| new_rel = replace_curie(name, rel) references[type].each do |reference| reference[new_rel] = reference.delete(rel) end end end end |
#to_h ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/hal_presenter/curie_collection.rb', line 45 def to_h { name: name, href: href, templated: templated } end |