Class: FellowshipOne::MemberHouseholdList

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ MemberHouseholdList

Constructor.

Options: :page - (optional) The page number to get. :reader - (optional) The Reader to use to load the data. :household_id - The household ID to pull the info for.

Parameters:

  • options

    A hash of options for loading the list.



15
16
17
18
19
20
21
# File 'lib/api/member_household_list.rb', line 15

def initialize(options)
  raise 'Household ID not specified' if options[:household_id].nil?

  #options[:page] ||= 1
  reader = options[:reader] || FellowshipOne::MemberHouseholdListReader.new(options)
  @json_data = reader.load_feed
end

Instance Method Details

#[](index) ⇒ User

Get the specified user.

Parameters:

  • index

    The index of the user to get.

Returns:

  • (User)


30
31
32
# File 'lib/api/member_household_list.rb', line 30

def [](index)
  Person.new( @json_data['people']['person'][index] ) if @json_data['people']['person'] and @json_data['people']['person'][index]
end

#all_namesObject



34
35
36
37
# File 'lib/api/member_household_list.rb', line 34

def all_names
  return [] unless @json_data['people']
  @json_data['people']['person'].collect { |person| [person['firstName'], person['lastName']].join(' ') }
end

#each(&block) ⇒ Object

This method is needed for Enumerable.



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

def each &block
  @json_data['people']['person'].each{ |person| yield( Person.new(person) )}
end

#empty?Boolean

Checks if the list is empty.

Returns:

  • (Boolean)

    True on empty, false otherwise.



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

def empty?
  #@json_data['person'].empty?
  self.count == 0 ? true : false
end

#idsObject

Get all the household ids in the list.

Returns:

  • An array of household ids.



58
59
60
# File 'lib/api/member_household_list.rb', line 58

def ids
  @json_data['people']['person'].collect { |person| person['@id'] }
end

#raw_dataObject

Access to the raw JSON data. This method is needed for merging lists.



65
66
67
# File 'lib/api/member_household_list.rb', line 65

def raw_data
  @json_data['people']['person']
end