Class: Drivenow::Car

Inherits:
Object
  • Object
show all
Defined in:
lib/drivenow/drivenow_car.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Car

initialize a new Car from a Hash that’s returned from the drive-now API. Example: “latitude”:“48.164372777778”, “longitude”:“11.594320833333”, “address”:“Biedersteiner Straße 29, 80802 München”, “auto”:“N”, “carName”:“Barbi”, “cit”:“4604”, “color”:“MIDNIGHT BLACK”, “fuelState”:“40”, “group”:“MINI”, “innerCleanliness”:“CLEAN”, “licensePlate”:“M -I 7396”, “model”:“MINI Cooper”, “personalName”:“MINI Cooper: Barbi”}

Raises:

  • (ArgumentError)


21
22
23
24
25
# File 'lib/drivenow/drivenow_car.rb', line 21

def initialize(hash)
	raise ArgumentError, 'hash must be a valid Hash with keys' if hash.nil? || hash.class != {}.class || hash.keys.count == 0
	
	@json = hash
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



3
4
5
# File 'lib/drivenow/drivenow_car.rb', line 3

def json
  @json
end

Instance Method Details

#addressObject

Gets the current address Example: “Biedersteiner Straße 29, 80802 München”



35
36
37
# File 'lib/drivenow/drivenow_car.rb', line 35

def address
	@address ||= json['position']['address']
end

#automatic?Boolean

Gets if it’s an automatic car or manual

Returns:

  • (Boolean)


40
41
42
# File 'lib/drivenow/drivenow_car.rb', line 40

def automatic?
	@automatic ||= json['auto'] == 'Y'
end

#cityObject

Gets the car’s city Example: “Berlin”



50
51
52
# File 'lib/drivenow/drivenow_car.rb', line 50

def city
	@city ||= json["cit"].to_s.capitalize
end

#cleanObject

Gets the car’s cleanliness state. “CLEAN” normally



77
78
79
# File 'lib/drivenow/drivenow_car.rb', line 77

def clean
	@clean ||= json['innerCleanliness']
end

#colorObject



44
45
46
# File 'lib/drivenow/drivenow_car.rb', line 44

def color
	@color ||= json['color'].capitalize
end

#fuel_stateObject

Gets the car’s fuel state in percent Example: “40%”



72
73
74
# File 'lib/drivenow/drivenow_car.rb', line 72

def fuel_state
	@fuel_state ||= "#{json['fuelState']}%"
end

#license_plateObject

Gets the car’s license plate (e.g. “M-I 7396”)



55
56
57
# File 'lib/drivenow/drivenow_car.rb', line 55

def license_plate
	@license ||= json['licensePlate'].gsub('  ', '')
end

#modelObject

Gets the car’s model (e.g. “MINI COOPER”)



60
61
62
# File 'lib/drivenow/drivenow_car.rb', line 60

def model
	@model ||= json['model']
end

#nameObject

Gets the personal Name and color of the car Example: “MINI Cooper: Barbi (MIDNIGHT BLACK)”



29
30
31
# File 'lib/drivenow/drivenow_car.rb', line 29

def name
	@name ||= "#{json['personalName']} (#{color})"
end

#positionObject

Gets the car’s current position Example: => ‘00.0000’, :longitude => ‘00.000’, :address => ‘Musterstraße 01234 Berlin’



66
67
68
# File 'lib/drivenow/drivenow_car.rb', line 66

def position
	@position ||= json['position']
end