Class: TheCity::PledgeList
- Includes:
- Enumerable
- Defined in:
- lib/api/pledge_list.rb
Instance Attribute Summary
Attributes inherited from ApiList
#current_page, #per_page, #total_entries, #total_pages
Instance Method Summary collapse
-
#[](index) ⇒ pledge
Get the specified pledge.
-
#all_names ⇒ Object
(also: #names)
All the pledges in the list.
-
#each(&block) ⇒ Object
This method is needed for Enumerable.
-
#empty? ⇒ Boolean
Checks if the list is empty.
-
#initialize(options = {}) ⇒ PledgeList
constructor
Constructor.
Methods inherited from ApiList
load, #next_page, #next_page!, #next_page?
Constructor Details
#initialize(options = {}) ⇒ PledgeList
Constructor.
Options:
:page - The page number to get.
:reader - The Reader to use to load the data.
:search - (optional) A pledge name to search on.
Examples:
PledgeList.new
PledgeList.new({:page => 2})
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/api/pledge_list.rb', line 22 def initialize( = {}) @options = @options[:page] ||= 1 @options[:reader] = TheCity::PledgeListReader.new(@options) if @options[:reader].nil? @json_data = @options[:reader].load_feed @total_entries = @json_data['total_entries'] @total_pages = @json_data['total_pages'] @per_page = @json_data['per_page'] @current_page = @json_data['current_page'] end |
Instance Method Details
#[](index) ⇒ pledge
Get the specified pledge.
49 50 51 |
# File 'lib/api/pledge_list.rb', line 49 def [](index) Pledge.new( @json_data['pledges'][index] ) if @json_data['pledges'][index] end |
#all_names ⇒ Object Also known as: names
All the pledges in the list.
38 39 40 |
# File 'lib/api/pledge_list.rb', line 38 def all_names @json_data['pledges'].collect { |pledge| pledge['user_name'] } end |
#each(&block) ⇒ Object
This method is needed for Enumerable.
55 56 57 |
# File 'lib/api/pledge_list.rb', line 55 def each &block @json_data['pledges'].each{ |pledge| yield( Pledge.new(pledge) )} end |
#empty? ⇒ Boolean
Checks if the list is empty.
66 67 68 |
# File 'lib/api/pledge_list.rb', line 66 def empty? @json_data['pledges'].empty? end |