Class: CollectionJSON::ItemBuilder
- Inherits:
-
Object
- Object
- CollectionJSON::ItemBuilder
- Defined in:
- lib/collection-json/builder.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
Instance Method Summary collapse
- #add_data(name, value = '', prompt = '') ⇒ Object
- #add_link(href, rel, name = '', prompt = '', render = '') ⇒ Object
-
#initialize(data, links) ⇒ ItemBuilder
constructor
A new instance of ItemBuilder.
Constructor Details
#initialize(data, links) ⇒ ItemBuilder
Returns a new instance of ItemBuilder.
57 58 59 60 |
# File 'lib/collection-json/builder.rb', line 57 def initialize(data, links) @data = data @links = links end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
55 56 57 |
# File 'lib/collection-json/builder.rb', line 55 def data @data end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
55 56 57 |
# File 'lib/collection-json/builder.rb', line 55 def links @links end |
Instance Method Details
#add_data(name, value = '', prompt = '') ⇒ Object
62 63 64 65 66 67 |
# File 'lib/collection-json/builder.rb', line 62 def add_data(name, value = '', prompt = '') data << {name: name}.tap do |data| data.merge!({'value' => value}) if value != '' data.merge!({'prompt' => prompt}) if prompt != '' end end |
#add_link(href, rel, name = '', prompt = '', render = '') ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/collection-json/builder.rb', line 69 def add_link(href, rel, name = '', prompt = '', render = '') href = CollectionJSON.add_host(href) links << Link.from_hash({'href' => href, 'rel' => rel}).tap do |link| link.merge!({'name' => name}) if name != '' link.merge!({'prompt' => prompt}) if prompt != '' link.merge!({'render' => render}) if render != '' end end |