Class: Leif::CollectionJson::Collection

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
Forwardable
Includes:
Linked
Defined in:
lib/leif/collection_json.rb

Defined Under Namespace

Classes: Item, Template

Instance Method Summary collapse

Methods included from Linked

#link_href, #link_relations, #links

Constructor Details

#initialize(body) ⇒ Collection

Returns a new instance of Collection.



25
26
27
# File 'lib/leif/collection_json.rb', line 25

def initialize(body)
  super body.fetch('collection')
end

Instance Method Details

#item_template(item) ⇒ Object



38
39
40
41
42
43
# File 'lib/leif/collection_json.rb', line 38

def item_template(item)
  template = template(item.fetch('href'), :put)
  item.fetch('data').inject(template) {|template, datum|
    template.fill_field datum.fetch('name'), datum.fetch('value')
  }
end

#itemsObject



29
30
31
32
# File 'lib/leif/collection_json.rb', line 29

def items
  return [] unless has_key?('items')
  fetch('items').map {|item| Item.new(item) }
end

#template(href = fetch('href'), method = :post) ⇒ Object



34
35
36
# File 'lib/leif/collection_json.rb', line 34

def template(href = fetch('href'), method = :post)
  Template.new(fetch('template'), href, method)
end