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