Class: TheCity::TagGroupList

Inherits:
ApiList
  • Object
show all
Includes:
Enumerable
Defined in:
lib/api/tag_group_list.rb

Instance Attribute Summary

Attributes inherited from ApiList

#current_page, #per_page, #total_entries, #total_pages

Instance Method Summary collapse

Methods inherited from ApiList

load, #next_page, #next_page!, #next_page?

Constructor Details

#initialize(options = {}) ⇒ TagGroupList

Constructor.

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})

Parameters:

  • options (defaults to: {})

    A hash of options for loading the list.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/api/tag_group_list.rb', line 21

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

Instance Method Details

#[](index) ⇒ TagGroup

Get the specified tag.

Parameters:

  • index

    The index of the tag to get.

Returns:

  • (TagGroup)


49
50
51
# File 'lib/api/tag_group_list.rb', line 49

def [](index)
  Group.new( @json_data['groups'][index] ) if @json_data['groups'][index]
end

#all_groupsObject Also known as: groups

All the tags in the list.

Returns:

  • array of group names.



37
38
39
40
# File 'lib/api/tag_group_list.rb', line 37

def all_groups
  return [] if @json_data['groups'].nil?
  @json_data['groups'].collect { |group| group['name'] }
end

#each(&block) ⇒ Object

This method is needed for Enumerable.



55
56
57
# File 'lib/api/tag_group_list.rb', line 55

def each &block
  @json_data['groups'].each{ |group| yield( Group.new(group) )}
end

#empty?Boolean

Checks if the list is empty.

Returns:

  • (Boolean)

    True on empty, false otherwise.



66
67
68
# File 'lib/api/tag_group_list.rb', line 66

def empty?
  @json_data['groups'].empty?
end