Sha256: 8b6b99695bd07092a10975617fb50eaaaf5c86dc8761a93890edffd295cb39d2

Contents?: true

Size: 1.37 KB

Versions: 12

Compression:

Stored size: 1.37 KB

Contents

module TheCity

  class AddressList < ApiList

    include Enumerable

    # Constructor.
    #
    # @param options A hash of options for loading the list.
    # 
    # Options:
    #   :page - The page number to get.
    #   :reader - The Reader to use to load the data.
    #
    #
    # Examples:
    #   AddressList.new
    #
    #   AddressList.new({:page => 2})
    #    
    def initialize(options = {}) 
      @options = 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
    
    
    # Get the specified note.
    #
    # @param index The index of the note to get.
    #
    # @return [Address]
    def [](index)
      Address.new( @json_data['addresses'][index] ) if @json_data['addresses'][index]
    end


    # This method is needed for Enumerable.
    def each &block
      @json_data['addresses'].each{ |address| yield( Address.new(address) )}
    end    
  
  
    # Alias the count method
    alias :size :count

    # Checks if the list is empty.
    #
    # @return True on empty, false otherwise.
    def empty?
      @json_data['addresses'].empty?
    end

  end
  
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
the-city-admin-0.7.1 lib/api/address_list.rb
the-city-admin-0.7.0 lib/api/address_list.rb
the-city-admin-0.6.9 lib/api/address_list.rb
the-city-admin-0.6.8 lib/api/address_list.rb
the-city-admin-0.6.7 lib/api/address_list.rb
the-city-admin-0.6.6 lib/api/address_list.rb
the-city-admin-0.6.5 lib/api/address_list.rb
the-city-admin-0.6.4 lib/api/address_list.rb
the-city-admin-0.6.3 lib/api/address_list.rb
the-city-admin-0.6.2 lib/api/address_list.rb
the-city-admin-0.6.1 lib/api/address_list.rb
the-city-admin-0.6.0 lib/api/address_list.rb