Class: Drivenow::Car
- Inherits:
-
Object
- Object
- Drivenow::Car
- Defined in:
- lib/drivenow/drivenow_car.rb
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
-
#address ⇒ Object
Gets the current address Example: “Biedersteiner Straße 29, 80802 München”.
-
#automatic? ⇒ Boolean
Gets if it’s an automatic car or manual.
-
#city ⇒ Object
Gets the car’s city Example: “Berlin”.
-
#clean ⇒ Object
Gets the car’s cleanliness state.
- #color ⇒ Object
-
#fuel_state ⇒ Object
Gets the car’s fuel state in percent Example: “40%”.
-
#initialize(hash) ⇒ Car
constructor
initialize a new Car from a Hash that’s returned from the drive-now API.
-
#license_plate ⇒ Object
Gets the car’s license plate (e.g. “M-I 7396”).
-
#model ⇒ Object
Gets the car’s model (e.g. “MINI COOPER”).
-
#name ⇒ Object
Gets the personal Name and color of the car Example: “MINI Cooper: Barbi (MIDNIGHT BLACK)”.
-
#position ⇒ Object
Gets the car’s current position Example: => ‘00.0000’, :longitude => ‘00.000’, :address => ‘Musterstraße 01234 Berlin’.
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”}
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
#json ⇒ Object (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
#address ⇒ Object
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
40 41 42 |
# File 'lib/drivenow/drivenow_car.rb', line 40 def automatic? @automatic ||= json['auto'] == 'Y' end |
#city ⇒ Object
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 |
#clean ⇒ Object
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 |
#color ⇒ Object
44 45 46 |
# File 'lib/drivenow/drivenow_car.rb', line 44 def color @color ||= json['color'].capitalize end |
#fuel_state ⇒ Object
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_plate ⇒ Object
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 |
#model ⇒ Object
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 |
#name ⇒ Object
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 |
#position ⇒ Object
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 |