Class: FellowshipOne::MergeableHouseholdList
- Inherits:
-
Object
- Object
- FellowshipOne::MergeableHouseholdList
- Includes:
- Enumerable
- Defined in:
- lib/api/mergeable_household_list.rb
Instance Method Summary collapse
-
#[](index) ⇒ household
Get the specified household.
-
#add(household_list) ⇒ Object
(also: #merge)
Adds a HouseholdList to this list.
-
#all_names ⇒ Object
(also: #names)
All the households in the list.
-
#each(&block) ⇒ Object
This method is needed for Enumerable.
-
#empty? ⇒ Boolean
Checks if the list is empty.
-
#ids ⇒ Object
Get all the household ids in the list.
-
#initialize ⇒ MergeableHouseholdList
constructor
Constructor.
-
#raw_data ⇒ Object
Access to the raw JSON data.
Constructor Details
#initialize ⇒ MergeableHouseholdList
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.
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_names ⇒ Object Also known as: names
All the households in the list.
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.
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 |
#ids ⇒ Object
Get all the household ids in the list.
56 57 58 |
# File 'lib/api/mergeable_household_list.rb', line 56 def ids (@json_data['household'].collect { |household| household['@id'] }).uniq end |
#raw_data ⇒ Object
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 |