Sha256: 2af06443545d0549d447e6480fc2d477b24c3072e0c3e1682f910431ed51cdc2

Contents?: true

Size: 1.64 KB

Versions: 12

Compression:

Stored size: 1.64 KB

Contents

module TheCity

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


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


    # Alias the count method
    alias :size :count

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

Version data entries

12 entries across 12 versions & 1 rubygems

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