Class: CollectionJSON::Collection
- Inherits:
-
Object
- Object
- CollectionJSON::Collection
- Defined in:
- lib/collection-json/collection.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#items ⇒ Object
Returns the value of attribute items.
-
#links ⇒ Object
Returns the value of attribute links.
-
#queries ⇒ Object
Returns the value of attribute queries.
-
#template ⇒ Object
Returns the value of attribute template.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #collection ⇒ Object
-
#initialize(href) ⇒ Collection
constructor
A new instance of Collection.
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(href) ⇒ Collection
Returns a new instance of Collection.
22 23 24 25 26 27 28 29 30 |
# File 'lib/collection-json/collection.rb', line 22 def initialize(href) @href = CollectionJSON.add_host(href) @version = COLLECTION_JSON_VERSION @items = [] @links = [] @queries = [] @error = nil @template = nil end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
9 10 11 |
# File 'lib/collection-json/collection.rb', line 9 def error @error end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
9 10 11 |
# File 'lib/collection-json/collection.rb', line 9 def href @href end |
#items ⇒ Object
Returns the value of attribute items.
9 10 11 |
# File 'lib/collection-json/collection.rb', line 9 def items @items end |
#links ⇒ Object
Returns the value of attribute links.
9 10 11 |
# File 'lib/collection-json/collection.rb', line 9 def links @links end |
#queries ⇒ Object
Returns the value of attribute queries.
9 10 11 |
# File 'lib/collection-json/collection.rb', line 9 def queries @queries end |
#template ⇒ Object
Returns the value of attribute template.
9 10 11 |
# File 'lib/collection-json/collection.rb', line 9 def template @template end |
#version ⇒ Object
Returns the value of attribute version.
9 10 11 |
# File 'lib/collection-json/collection.rb', line 9 def version @version end |
Class Method Details
.from_hash(hash) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/collection-json/collection.rb', line 12 def self.from_hash(hash) self.new(hash[ROOT_NODE]['href']).tap do |collection| %w{items links queries error template}.each do |attribute| if hash[ROOT_NODE][attribute] collection.send("#{attribute}=", hash[ROOT_NODE][attribute]) end end end end |
Instance Method Details
#collection ⇒ Object
52 53 54 |
# File 'lib/collection-json/collection.rb', line 52 def collection {ROOT_NODE => body} end |
#to_json(*args) ⇒ Object
56 57 58 |
# File 'lib/collection-json/collection.rb', line 56 def to_json(*args) collection.to_json(args) end |