Class: TheCity::UserSkillList

Inherits:
ApiList
  • Object
show all
Includes:
Enumerable
Defined in:
lib/api/user_skill_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 = {}) ⇒ UserSkillList

Constructor.

Options:

:user_id - The ID of the user to load the user skills for. (required)
:page - The page number to get.
:reader - The Reader to use to load the data.

Examples:

UserSkillList.new({:user_id => 12345})

UserSkillList.new({:user_id => 12345, :page => 2})

Parameters:

  • options (defaults to: {})

    A hash of options for loading the list.



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

def initialize(options = {}) 
  @options = options
  @options[:page] ||= 1
  @options[:reader] = TheCity::UserSkillListReader.new(@options) if @options[:reader].nil?
  @json_data = @options[:reader].load_feed 

  @user_id = options[:user_id] || nil
  @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) ⇒ UserSkill

Get the specified skill.

Parameters:

  • index

    The index of the skill to get.

Returns:



51
52
53
# File 'lib/api/user_skill_list.rb', line 51

def [](index)
  UserSkill.new( @json_data['skills'][index].merge({:user_id => @user_id}) ) if @json_data['skills'][index]
end

#all_skillsObject Also known as: skills

All the skills in the list.

Returns:

  • array of skill names.



39
40
41
42
# File 'lib/api/user_skill_list.rb', line 39

def all_skills
  return [] if @json_data['skills'].nil?
  @json_data['skills'].collect { |skill| skill['name'] }
end

#each(&block) ⇒ Object

This method is needed for Enumerable.



57
58
59
# File 'lib/api/user_skill_list.rb', line 57

def each &block
  @json_data['skills'].each{ |skill| yield( UserSkill.new(skill.merge({:user_id => @user_id})) ) }
end

#empty?Boolean

Checks if the list is empty.

Returns:

  • (Boolean)

    True on empty, false otherwise.



67
68
69
# File 'lib/api/user_skill_list.rb', line 67

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