Class: Pinch::Building

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#addressString (readonly)

TODO: Write general description for this method

Returns:



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

def address
  @address
end

#cityString (readonly)

TODO: Write general description for this method

Returns:



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

def city
  @city
end

#countryString (readonly)

TODO: Write general description for this method

Returns:



28
29
30
# File 'lib/pinch/models/building.rb', line 28

def country
  @country
end

#latitudeFloat (readonly)

TODO: Write general description for this method

Returns:

  • (Float)


32
33
34
# File 'lib/pinch/models/building.rb', line 32

def latitude
  @latitude
end

#longitudeFloat (readonly)

TODO: Write general description for this method

Returns:

  • (Float)


36
37
38
# File 'lib/pinch/models/building.rb', line 36

def longitude
  @longitude
end

#nameString (readonly)

TODO: Write general description for this method

Returns:



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

def name
  @name
end

#referenceString (readonly)

TODO: Write general description for this method

Returns:



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

def reference
  @reference
end

#zip_codeString (readonly)

TODO: Write general description for this method

Returns:



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_mapObject

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_jsonObject

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