Class: CollectionJson::Collection
- Inherits:
-
Object
- Object
- CollectionJson::Collection
- Extended by:
- FunkyAccessor
- Defined in:
- lib/collection_json/collection.rb
Instance Method Summary collapse
-
#initialize(items) ⇒ Collection
constructor
A new instance of Collection.
- #item_representations ⇒ Object
- #representation ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(items) ⇒ Collection
Returns a new instance of Collection.
6 7 8 9 10 11 |
# File 'lib/collection_json/collection.rb', line 6 def initialize items @version = "1.0" @items = items.map { |i| Item.new(i) } @template = @items.first.blank_template if @items.any? @links = [] end |
Instance Method Details
#item_representations ⇒ Object
30 31 32 |
# File 'lib/collection_json/collection.rb', line 30 def item_representations items.map &:singular_representation end |
#representation ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/collection_json/collection.rb', line 13 def representation collection = { version: version, href: href, links: links, items: item_representations } collection.merge!({template: {data: template}}) if template {collection: collection} end |
#to_json ⇒ Object
26 27 28 |
# File 'lib/collection_json/collection.rb', line 26 def to_json representation.to_json end |