Class: Multicity::Car
- Inherits:
-
Object
- Object
- Multicity::Car
- Defined in:
- lib/multicity/multicity_car.rb
Overview
-
model: normally “Citroen C-Zero”
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#license_plate ⇒ Object
Returns the value of attribute license_plate.
-
#model ⇒ Object
Returns the value of attribute model.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
-
#initialize(hash = nil) ⇒ Car
constructor
Creates a new Car object.
- #valid? ⇒ Boolean
Constructor Details
#initialize(hash = nil) ⇒ Car
Creates a new Car object. The hash can be set to a value from the Multicity-API. If the hash is nil, the car will not have any data Example hash {
"lat" => "52.5359483",
"iconName" => "carIcon",
"iconNameSelected" => "carIconSelected",
"lng" => "13.4432250",
"hal2option" => {
"mouseout" => "hideToolTip",
"maxZoom" => "",
"clustername" => "multicitycluster",
"click" => "showMarkerInfos",
"id" => "284964",
"minZoom" => "4",
"tooltip" => "'Citroën C-Zero (B-MC 1694)'",
"bende" => "1359122400",
"StationInfoTyp" => "HM_AUTO_INFO",
"rclick" => false,
"dblclick" => false,
"objecttyp" => "carpos",
"objectname" => "multicitymarker",
"draggable" => false,
"mouseover" => "showToolTip",
"openinfo" => "showMarkerInfos",
"banfang" => "1359118800"
}
}
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/multicity/multicity_car.rb', line 39 def initialize hash = nil @json = hash unless hash.nil? tooltip = json["hal2option"]["tooltip"].gsub "'", "" if tooltip != "false" self.position = { :lat => json["lat"], :lon => json["lng"] } self.id = json["hal2option"]["id"] tips = tooltip.split(" ") if (tips.count == 2) self.model = tips[0] self.license_plate = tips[1].to_s.gsub("(", "").gsub(")", "") end end end end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/multicity/multicity_car.rb', line 9 def id @id end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
8 9 10 |
# File 'lib/multicity/multicity_car.rb', line 8 def json @json end |
#license_plate ⇒ Object
Returns the value of attribute license_plate.
9 10 11 |
# File 'lib/multicity/multicity_car.rb', line 9 def license_plate @license_plate end |
#model ⇒ Object
Returns the value of attribute model.
9 10 11 |
# File 'lib/multicity/multicity_car.rb', line 9 def model @model end |
#position ⇒ Object
Returns the value of attribute position.
9 10 11 |
# File 'lib/multicity/multicity_car.rb', line 9 def position @position end |
Instance Method Details
#valid? ⇒ Boolean
55 56 57 |
# File 'lib/multicity/multicity_car.rb', line 55 def valid? !position.nil? && !position[:lat].nil? && !position[:lon].nil? end |