Class: Pinch::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/pinch/models/person.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(firstname = nil, lastname = nil, home_phone_number = nil, mobile_phone_number = nil, role = nil) ⇒ Person

Returns a new instance of Person.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pinch/models/person.rb', line 26

def initialize(firstname = nil,
               lastname = nil,
               home_phone_number = nil,
               mobile_phone_number = nil,
               role = nil)
  @firstname = firstname
  @lastname = lastname
  @home_phone_number = home_phone_number
  @mobile_phone_number = mobile_phone_number
  @role = role

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



39
40
41
# File 'lib/pinch/models/person.rb', line 39

def method_missing(method_name)
  puts "There is no method called '#{method_name}'."
end

Instance Attribute Details

#firstnameString (readonly)

TODO: Write general description for this method

Returns:



8
9
10
# File 'lib/pinch/models/person.rb', line 8

def firstname
  @firstname
end

#home_phone_numberString (readonly)

The landline phone number of the resident or manager

Returns:



16
17
18
# File 'lib/pinch/models/person.rb', line 16

def home_phone_number
  @home_phone_number
end

#lastnameString (readonly)

TODO: Write general description for this method

Returns:



12
13
14
# File 'lib/pinch/models/person.rb', line 12

def lastname
  @lastname
end

#mobile_phone_numberString (readonly)

TODO: Write general description for this method

Returns:



20
21
22
# File 'lib/pinch/models/person.rb', line 20

def mobile_phone_number
  @mobile_phone_number
end

#roleString (readonly)

Caretaker, Resident, Manager, ThirdParty

Returns:



24
25
26
# File 'lib/pinch/models/person.rb', line 24

def role
  @role
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/pinch/models/person.rb', line 50

def self.from_hash(hash)
  if hash == nil
    nil
  else
    # Extract variables from the hash
    firstname = hash["firstname"]
    lastname = hash["lastname"]
    home_phone_number = hash["home_phone_number"]
    mobile_phone_number = hash["mobile_phone_number"]
    role = hash["role"]
    # Create object from extracted values
    Person.new(firstname,
               lastname,
               home_phone_number,
               mobile_phone_number,
               role)
  end
end

Instance Method Details

#key_mapObject

Defines the key map for json serialization



70
71
72
73
74
75
76
77
78
# File 'lib/pinch/models/person.rb', line 70

def key_map
  hash = {}
  hash['firstname'] = firstname
  hash['lastname'] = lastname
  hash['home_phone_number'] = home_phone_number
  hash['mobile_phone_number'] = mobile_phone_number
  hash['role'] = role
  hash
end

#to_jsonObject

Creates JSON of the curent object



44
45
46
47
# File 'lib/pinch/models/person.rb', line 44

def to_json
  hash = key_map
  hash.to_json
end