Class: Multicity::Car

Inherits:
Object
  • Object
show all
Defined in:
lib/multicity/multicity_car.rb

Overview

  • model: normally “Citroen C-Zero”

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/multicity/multicity_car.rb', line 9

def id
  @id
end

#jsonObject (readonly)

Returns the value of attribute json.



8
9
10
# File 'lib/multicity/multicity_car.rb', line 8

def json
  @json
end

#license_plateObject

Returns the value of attribute license_plate.



9
10
11
# File 'lib/multicity/multicity_car.rb', line 9

def license_plate
  @license_plate
end

#modelObject

Returns the value of attribute model.



9
10
11
# File 'lib/multicity/multicity_car.rb', line 9

def model
  @model
end

#positionObject

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

Returns:

  • (Boolean)


55
56
57
# File 'lib/multicity/multicity_car.rb', line 55

def valid?
	!position.nil? && !position[:lat].nil? && !position[:lon].nil?
end