Class: Pinch::Building
- Inherits:
-
Object
- Object
- Pinch::Building
- Defined in:
- lib/pinch/models/building.rb
Instance Attribute Summary collapse
-
#address ⇒ String
readonly
TODO: Write general description for this method.
-
#city ⇒ String
readonly
TODO: Write general description for this method.
-
#country ⇒ String
readonly
TODO: Write general description for this method.
-
#latitude ⇒ Float
readonly
TODO: Write general description for this method.
-
#longitude ⇒ Float
readonly
TODO: Write general description for this method.
-
#name ⇒ String
readonly
TODO: Write general description for this method.
-
#reference ⇒ String
readonly
TODO: Write general description for this method.
-
#zip_code ⇒ String
readonly
TODO: Write general description for this method.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
Instance Method Summary collapse
-
#initialize(reference = nil, name = nil, address = nil, zip_code = nil, city = nil, country = nil, latitude = nil, longitude = nil) ⇒ Building
constructor
A new instance of Building.
-
#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(reference = nil, name = nil, address = nil, zip_code = nil, city = nil, country = nil, latitude = nil, longitude = nil) ⇒ Building
Returns a new instance of Building.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pinch/models/building.rb', line 38 def initialize(reference = nil, name = nil, address = nil, zip_code = nil, city = nil, country = nil, latitude = nil, longitude = nil) @reference = reference @name = name @address = address @zip_code = zip_code @city = city @country = country @latitude = latitude @longitude = longitude end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
57 58 59 |
# File 'lib/pinch/models/building.rb', line 57 def method_missing(method_name) puts "There is no method called '#{method_name}'." end |
Instance Attribute Details
#address ⇒ String (readonly)
TODO: Write general description for this method
16 17 18 |
# File 'lib/pinch/models/building.rb', line 16 def address @address end |
#city ⇒ String (readonly)
TODO: Write general description for this method
24 25 26 |
# File 'lib/pinch/models/building.rb', line 24 def city @city end |
#country ⇒ String (readonly)
TODO: Write general description for this method
28 29 30 |
# File 'lib/pinch/models/building.rb', line 28 def country @country end |
#latitude ⇒ Float (readonly)
TODO: Write general description for this method
32 33 34 |
# File 'lib/pinch/models/building.rb', line 32 def latitude @latitude end |
#longitude ⇒ Float (readonly)
TODO: Write general description for this method
36 37 38 |
# File 'lib/pinch/models/building.rb', line 36 def longitude @longitude end |
#name ⇒ String (readonly)
TODO: Write general description for this method
12 13 14 |
# File 'lib/pinch/models/building.rb', line 12 def name @name end |
#reference ⇒ String (readonly)
TODO: Write general description for this method
8 9 10 |
# File 'lib/pinch/models/building.rb', line 8 def reference @reference end |
#zip_code ⇒ String (readonly)
TODO: Write general description for this method
20 21 22 |
# File 'lib/pinch/models/building.rb', line 20 def zip_code @zip_code end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pinch/models/building.rb', line 68 def self.from_hash(hash) if hash == nil nil else # Extract variables from the hash reference = hash["reference"] name = hash["name"] address = hash["address"] zip_code = hash["zip_code"] city = hash["city"] country = hash["country"] latitude = hash["latitude"] longitude = hash["longitude"] # Create object from extracted values Building.new(reference, name, address, zip_code, city, country, latitude, longitude) end end |
Instance Method Details
#key_map ⇒ Object
Defines the key map for json serialization
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/pinch/models/building.rb', line 94 def key_map hash = {} hash['reference'] = reference hash['name'] = name hash['address'] = address hash['zip_code'] = zip_code hash['city'] = city hash['country'] = country hash['latitude'] = latitude hash['longitude'] = longitude hash end |
#to_json ⇒ Object
Creates JSON of the curent object
62 63 64 65 |
# File 'lib/pinch/models/building.rb', line 62 def to_json hash = key_map hash.to_json end |