Class: FellowshipOne::HouseholdList

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ HouseholdList

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.



17
18
19
20
21
22
23
24
25
26
# File 'lib/api/household_list.rb', line 17

def initialize(options)
  #options[:page] ||= 1
  reader = options[:reader] || FellowshipOne::HouseholdListReader.new(options)
  @json_data = reader.load_feed

  @count = @json_data['@count'].to_i
  @page_number = @json_data['@pageNumber'].to_i
  @total_records = @json_data['@totalRecords'].to_i
  @additional_pages = @json_data['@additionalPages'].to_i
end

Instance Attribute Details

#additional_pagesObject (readonly)

Returns the value of attribute additional_pages.



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

def additional_pages
  @additional_pages
end

#countObject (readonly) Also known as: size

Returns the value of attribute count.



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

def count
  @count
end

#page_numberObject (readonly)

Returns the value of attribute page_number.



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

def page_number
  @page_number
end

#total_recordsObject (readonly)

Returns the value of attribute total_records.



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

def total_records
  @total_records
end

Instance Method Details

#[](index) ⇒ User

Get the specified user.

Parameters:

  • index

    The index of the user to get.

Returns:

  • (User)


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

def [](index)
  Household.new( @json_data['household'][index] ) if @json_data['household'] and @json_data['household'][index]
end

#all_namesObject



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

def all_names
  return [] unless @json_data['household']
  @json_data['household'].collect { |household| household['householdName'] }
end

#each(&block) ⇒ Object

This method is needed for Enumerable.



45
46
47
# File 'lib/api/household_list.rb', line 45

def each &block
  @json_data['household'].each{ |household| yield( Household.new(household) )}
end

#empty?Boolean

Checks if the list is empty.

Returns:

  • (Boolean)

    True on empty, false otherwise.



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

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.



63
64
65
# File 'lib/api/household_list.rb', line 63

def ids
  (@json_data['household'].collect { |household| household['@id'] }).uniq
end

#raw_dataObject

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



70
71
72
# File 'lib/api/household_list.rb', line 70

def raw_data
  @json_data
end