Class: WpApiClient::Collection
- Inherits:
-
Object
- Object
- WpApiClient::Collection
- Includes:
- Enumerable
- Defined in:
- lib/wp_api_client/collection.rb
Instance Attribute Summary collapse
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#total_available ⇒ Object
Returns the value of attribute total_available.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(resources, headers) ⇒ Collection
constructor
A new instance of Collection.
- #method_missing(sym) ⇒ Object
- #next_page ⇒ Object
- #previous_page ⇒ Object
Constructor Details
#initialize(resources, headers) ⇒ Collection
Returns a new instance of Collection.
7 8 9 10 11 |
# File 'lib/wp_api_client/collection.rb', line 7 def initialize(resources, headers) @resources = resources @links = parse_link_header(headers['Link']) @total_available = headers['X-WP-TOTAL'].to_i end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym) ⇒ Object
25 26 27 |
# File 'lib/wp_api_client/collection.rb', line 25 def method_missing(sym) @resources.send(sym) end |
Instance Attribute Details
#resources ⇒ Object
Returns the value of attribute resources.
5 6 7 |
# File 'lib/wp_api_client/collection.rb', line 5 def resources @resources end |
#total_available ⇒ Object
Returns the value of attribute total_available.
5 6 7 |
# File 'lib/wp_api_client/collection.rb', line 5 def total_available @total_available end |
Instance Method Details
#each(&block) ⇒ Object
13 14 15 |
# File 'lib/wp_api_client/collection.rb', line 13 def each(&block) @resources.each{|p| block.call(p)} end |
#next_page ⇒ Object
17 18 19 |
# File 'lib/wp_api_client/collection.rb', line 17 def next_page @links[:next] && @links[:next] end |
#previous_page ⇒ Object
21 22 23 |
# File 'lib/wp_api_client/collection.rb', line 21 def previous_page @links[:prev] && @links[:prev] end |