Class: TheCity::AddressList
- Includes:
- Enumerable
- Defined in:
- lib/api/address_list.rb
Instance Attribute Summary
Attributes inherited from ApiList
#current_page, #per_page, #total_entries, #total_pages
Instance Method Summary collapse
-
#[](index) ⇒ Address
Get the specified note.
-
#each(&block) ⇒ Object
This method is needed for Enumerable.
-
#empty? ⇒ Boolean
Checks if the list is empty.
-
#initialize(options = {}) ⇒ AddressList
constructor
Constructor.
Methods inherited from ApiList
load, #next_page, #next_page!, #next_page?
Constructor Details
#initialize(options = {}) ⇒ AddressList
Constructor.
Options:
:page - The page number to get.
:reader - The Reader to use to load the data.
Examples:
AddressList.new
AddressList.new({:page => 2})
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/api/address_list.rb', line 21 def initialize( = {}) @options = @options[:reader] = TheCity::AddressListReader.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) ⇒ Address
Get the specified note.
38 39 40 |
# File 'lib/api/address_list.rb', line 38 def [](index) Address.new( @json_data['addresses'][index] ) if @json_data['addresses'][index] end |
#each(&block) ⇒ Object
This method is needed for Enumerable.
44 45 46 |
# File 'lib/api/address_list.rb', line 44 def each &block @json_data['addresses'].each{ |address| yield( Address.new(address) )} end |
#empty? ⇒ Boolean
Checks if the list is empty.
55 56 57 |
# File 'lib/api/address_list.rb', line 55 def empty? @json_data['addresses'].empty? end |