Class: Telapi::ResourceCollection
- Inherits:
-
Object
- Object
- Telapi::ResourceCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/telapi/resource_collection.rb
Overview
This class wraps Resource objects and provides Enumerable functionality.
Note that TelAPI collections are automatically separated into pages of results, see www.telapi.com/docs/api/rest/overview/response/.
Currently this container class does not automatically handle the retrieving of a previous/next page of results. However, all of the Resource classes that provide a list
method allow you to specify the current page and size.
Instance Attribute Summary collapse
-
#end ⇒ Object
readonly
Returns the value of attribute end.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#num_pages ⇒ Object
readonly
Returns the value of attribute num_pages.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#page_size ⇒ Object
readonly
Returns the value of attribute page_size.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(attributes, collection_node_name, resource_type) ⇒ ResourceCollection
constructor
A new instance of ResourceCollection.
Constructor Details
#initialize(attributes, collection_node_name, resource_type) ⇒ ResourceCollection
Returns a new instance of ResourceCollection.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/telapi/resource_collection.rb', line 18 def initialize(attributes, collection_node_name, resource_type) @page = attributes['page'] @num_pages = attributes['num_pages'] @page_size = attributes['page_size'] @total = attributes['total'] @start = attributes['start'] @end = attributes['end'] @items = [] attributes[collection_node_name].each do |item| @items << resource_type.send(:new, item) end if attributes[collection_node_name] end |
Instance Attribute Details
#end ⇒ Object (readonly)
Returns the value of attribute end.
16 17 18 |
# File 'lib/telapi/resource_collection.rb', line 16 def end @end end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
16 17 18 |
# File 'lib/telapi/resource_collection.rb', line 16 def items @items end |
#num_pages ⇒ Object (readonly)
Returns the value of attribute num_pages.
16 17 18 |
# File 'lib/telapi/resource_collection.rb', line 16 def num_pages @num_pages end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
16 17 18 |
# File 'lib/telapi/resource_collection.rb', line 16 def page @page end |
#page_size ⇒ Object (readonly)
Returns the value of attribute page_size.
16 17 18 |
# File 'lib/telapi/resource_collection.rb', line 16 def page_size @page_size end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
16 17 18 |
# File 'lib/telapi/resource_collection.rb', line 16 def start @start end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
16 17 18 |
# File 'lib/telapi/resource_collection.rb', line 16 def total @total end |
Instance Method Details
#each ⇒ Object
34 35 36 |
# File 'lib/telapi/resource_collection.rb', line 34 def each @items.each { |i| yield i } end |