Class: ShelbyArena::Family

Inherits:
ApiObject show all
Defined in:
lib/api/family.rb

Instance Attribute Summary

Attributes inherited from ApiObject

#error_messages, #marked_for_destruction

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiObject

#initialize_from_json_object

Constructor Details

#initialize(reader = nil, options = {}) ⇒ Family

Constructor.

Parameters:

  • reader (optional) (defaults to: nil)

    The object that has the data. This can be a PersonReader or Hash object.

  • options (optional) (defaults to: {})

    Options for including more information.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/api/family.rb', line 27

def initialize(reader = nil, options = {})  
  #@writer_object = FamilyWriter
  if reader.is_a?(FamilyReader)
    initialize_from_json_object(reader.load_data['Family'])        
  elsif reader.is_a?(Hash)        
    initialize_from_json_object(reader)
  else # new empty
    raise 'Not sure about this one yet'
    # reader = FamilyReader.new
    # initialize_from_json_object(reader.load_new['family'])
  end      

  # The data loaded from family_members is useless.  It is best to just reload all the family 
  # members as person objects so all attributes are set.     
  # fm[0] is 'Person'
  # fm[1] is a Hash of person info to match some, not all, of the attributes above.
  method_to_call = "#{ShelbyArena::attr_underscore('family_members')}="
  self.send(method_to_call, self.family_members.collect { |fm| ShelbyArena::Person.load_by_id(fm[1]['PersonID']) })       
end

Class Method Details

.load_by_id(family_id) ⇒ Object

Loads the family by the specified ID.

Returns a new Family object.

Parameters:

  • family

    The ID of the family to load.



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

def self.load_by_id(family_id)
  reader = FamilyReader.new(family_id)
  self.new(reader)
rescue
  nil      
end