Sha256: fa56b4616e19ffcbaf96d6707056bb0be46004ffaf92e3a740f63c74cab58d6f

Contents?: true

Size: 1.63 KB

Versions: 12

Compression:

Stored size: 1.63 KB

Contents

module TheCity

  class TagGroupList < ApiList

    include Enumerable

    # Constructor.
    #
    # @param options A hash of options for loading the list.
    # 
    # Options:
    #   :tag_id - The tag ID to load the groups for. (Required)
    #   :page - The page number to get.
    #
    #
    # Examples:
    #   SkilledUserList.new
    #
    #   SkilledUserList.new({:page => 2})
    #    
    def initialize(options = {}) 
      @options = options
      @options[:page] ||= 1
      @options[:reader] = TheCity::TagGroupListReader.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 tags in the list.
    #
    # @return array of group names.
    def all_groups
      return [] if @json_data['groups'].nil?
      @json_data['groups'].collect { |group| group['name'] }
    end
    alias :groups :all_groups
    
    
    # Get the specified tag.
    #
    # @param index The index of the tag to get.
    #
    # @return [TagGroup]
    def [](index)
      Group.new( @json_data['groups'][index] ) if @json_data['groups'][index]
    end


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


    # Alias the count method
    alias :size :count

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

Version data entries

12 entries across 12 versions & 1 rubygems

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