Class: WpApiClient::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wp_api_client/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#resourcesObject

Returns the value of attribute resources.



5
6
7
# File 'lib/wp_api_client/collection.rb', line 5

def resources
  @resources
end

#total_availableObject

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_pageObject



17
18
19
# File 'lib/wp_api_client/collection.rb', line 17

def next_page
  @links[:next] && @links[:next]
end

#previous_pageObject



21
22
23
# File 'lib/wp_api_client/collection.rb', line 21

def previous_page
  @links[:prev] && @links[:prev]
end