Class: Pinch::Person
- Inherits:
-
Object
- Object
- Pinch::Person
- Defined in:
- lib/pinch/models/person.rb
Instance Attribute Summary collapse
-
#firstname ⇒ String
readonly
TODO: Write general description for this method.
-
#home_phone_number ⇒ String
readonly
The landline phone number of the resident or manager.
-
#lastname ⇒ String
readonly
TODO: Write general description for this method.
-
#mobile_phone_number ⇒ String
readonly
TODO: Write general description for this method.
-
#role ⇒ String
readonly
Caretaker, Resident, Manager, ThirdParty.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
Instance Method Summary collapse
-
#initialize(firstname = nil, lastname = nil, home_phone_number = nil, mobile_phone_number = nil, role = nil) ⇒ Person
constructor
A new instance of Person.
-
#key_map ⇒ Object
Defines the key map for json serialization.
- #method_missing(method_name) ⇒ Object
-
#to_json ⇒ Object
Creates JSON of the curent object.
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
#firstname ⇒ String (readonly)
TODO: Write general description for this method
8 9 10 |
# File 'lib/pinch/models/person.rb', line 8 def firstname @firstname end |
#home_phone_number ⇒ String (readonly)
The landline phone number of the resident or manager
16 17 18 |
# File 'lib/pinch/models/person.rb', line 16 def home_phone_number @home_phone_number end |
#lastname ⇒ String (readonly)
TODO: Write general description for this method
12 13 14 |
# File 'lib/pinch/models/person.rb', line 12 def lastname @lastname end |
#mobile_phone_number ⇒ String (readonly)
TODO: Write general description for this method
20 21 22 |
# File 'lib/pinch/models/person.rb', line 20 def mobile_phone_number @mobile_phone_number end |
#role ⇒ String (readonly)
Caretaker, Resident, Manager, ThirdParty
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_map ⇒ Object
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_json ⇒ Object
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 |