Class: CollectionJSON::ItemBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/collection-json/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, links) ⇒ ItemBuilder

Returns a new instance of ItemBuilder.



54
55
56
57
# File 'lib/collection-json/builder.rb', line 54

def initialize(data, links)
  @data = data
  @links = links
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



52
53
54
# File 'lib/collection-json/builder.rb', line 52

def data
  @data
end

Returns the value of attribute links.



52
53
54
# File 'lib/collection-json/builder.rb', line 52

def links
  @links
end

Instance Method Details

#add_data(name, params = {}) ⇒ Object



59
60
61
62
# File 'lib/collection-json/builder.rb', line 59

def add_data(name, params = {})
  params.merge!({'name' => name})
  data << params
end


64
65
66
67
# File 'lib/collection-json/builder.rb', line 64

def add_link(href, rel, params = {})
  params.merge!({'rel' => rel, 'href' => href})
  links << params
end