Sha256: 64f98af6217490141e0757fa070ee411b285eeed70aaf381af0334afcc3d8aaa

Contents?: true

Size: 1.68 KB

Versions: 6

Compression:

Stored size: 1.68 KB

Contents

module TheCity

  class DonationList < 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.
    #   :search -  (optional) A donation name to search on.
    #
    #
    # Examples:
    #   DonationList.new
    #
    #   DonationList.new({:page => 2})
    #    
    def initialize(options = {}) 
      @options = options
      @options[:page] ||= 1
      @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
    
    
    # All the donations in the list.
    #
    # @return array of donation names.
    def all_names
      @json_data['donations'].collect { |donation| donation['user_name'] }
    end
    alias :names :all_names
    
    
    # Get the specified donation.
    #
    # @param index The index of the donation to get.
    #
    # @return [donation]
    def [](index)
      Donation.new( @json_data['donations'][index] ) if @json_data['donations'][index]
    end


    # This method is needed for Enumerable.
    def each &block
      @json_data['donations'].each{ |donation| yield( Donation.new(donation) )}
    end    


    # Alias the count method
    alias :size :count

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
the-city-admin-0.6.5 lib/api/donation_list.rb
the-city-admin-0.6.4 lib/api/donation_list.rb
the-city-admin-0.6.3 lib/api/donation_list.rb
the-city-admin-0.6.2 lib/api/donation_list.rb
the-city-admin-0.6.1 lib/api/donation_list.rb
the-city-admin-0.6.0 lib/api/donation_list.rb