Class: FellowshipOne::MergeableHouseholdList

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

Instance Method Summary collapse

Constructor Details

#initializeMergeableHouseholdList

Constructor.



9
10
11
12
# File 'lib/api/mergeable_household_list.rb', line 9

def initialize
  @json_data = { 'household' => [] }
   # commented out until can figure out what he was doing here.
end

Instance Method Details

#[](index) ⇒ household

Get the specified household.

Parameters:

  • index

    The index of the household to get.

Returns:

  • (household)


31
32
33
# File 'lib/api/mergeable_household_list.rb', line 31

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

#add(household_list) ⇒ Object Also known as: merge

Adds a HouseholdList to this list.



71
72
73
# File 'lib/api/mergeable_household_list.rb', line 71

def add(household_list)
  @json_data['household'] += household_list.raw_data['household']
end

#all_namesObject Also known as: names

All the households in the list.

Returns:

  • array of names (first last).



18
19
20
21
# File 'lib/api/mergeable_household_list.rb', line 18

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.



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

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.



47
48
49
50
# File 'lib/api/mergeable_household_list.rb', line 47

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

#idsObject

Get all the household ids in the list.

Returns:

  • An array of household ids.



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

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.



64
65
66
# File 'lib/api/mergeable_household_list.rb', line 64

def raw_data
  @json_data
end