Class: TheCity::UserFamilyList

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

Instance Attribute Summary collapse

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 = {}) ⇒ UserFamilyList

Constructor.

Options:

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

Examples:

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

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

Parameters:

  • options (defaults to: {})

    A hash of options for loading the list.



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

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

  @id = @json_data['id']
  @created_at = @json_data['created_at']
  @external_id = @json_data['external_id']
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



7
8
9
# File 'lib/api/user_family_list.rb', line 7

def created_at
  @created_at
end

#external_idObject (readonly)

Returns the value of attribute external_id.



7
8
9
# File 'lib/api/user_family_list.rb', line 7

def external_id
  @external_id
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/api/user_family_list.rb', line 7

def id
  @id
end

Instance Method Details

#[](index) ⇒ UserFamilyMember

Get the specified family member.

Parameters:

  • index

    The index of the family member to get.

Returns:



50
51
52
# File 'lib/api/user_family_list.rb', line 50

def [](index)      
  UserFamilyMember.new( @json_data['family_members'][index] ) if @json_data['family_members'][index]
end

#all_namesObject Also known as: names

All the famly member names in the list.

Returns:

  • array of names.



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

def all_names
  @json_data['family_members'].collect { |user| user['name'] }
end

#each(&block) ⇒ Object

This method is needed for Enumerable.



56
57
58
# File 'lib/api/user_family_list.rb', line 56

def each &block
  @json_data['family_members'].each{ |member| yield( UserFamilyMember.new(member) )}
end

#empty?Boolean

Checks if the list is empty.

Returns:

  • (Boolean)

    True on empty, false otherwise.



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

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