Class: CarvoyantAPI::DataPoint
- Inherits:
-
Object
- Object
- CarvoyantAPI::DataPoint
- Defined in:
- lib/carvoyant_api/resources/data_point.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#translated_value ⇒ Object
readonly
Returns the value of attribute translated_value.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#waypoint ⇒ Object
readonly
Returns the value of attribute waypoint.
Instance Method Summary collapse
-
#initialize(attributes = {}, unit_format = :metric) ⇒ DataPoint
constructor
A new instance of DataPoint.
Constructor Details
#initialize(attributes = {}, unit_format = :metric) ⇒ DataPoint
Returns a new instance of DataPoint.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/carvoyant_api/resources/data_point.rb', line 6 def initialize(attributes = {}, unit_format = :metric) @id = attributes[:id] @timestamp = attributes[:timestamp] @key = attributes[:key] @value = attributes[:value] @translated_value = attributes[:translatedValue] case @key when 'GEN_WAYPOINT' latitude, longitude = @value.split(',') @waypoint = Waypoint.new(timestamp: @timestamp, latitude: latitude, longitude: longitude) when 'GEN_ENGINE_COOLANT_TEMP' @translated_value = unit_format == :imperial ? Unit(@translated_value.gsub(' ', '')) : Unit(@translated_value.gsub(' ', '')).convert_to('degC') @value = @translated_value.scalar.to_f @translated_value = @translated_value.to_s('%.2f') when 'GEN_SPEED' @translated_value = unit_format == :imperial ? Unit(@translated_value) : Unit(@translated_value).convert_to('kph') @value = @translated_value.scalar.to_f @translated_value = @translated_value.to_s('%.2f') end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/carvoyant_api/resources/data_point.rb', line 4 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/carvoyant_api/resources/data_point.rb', line 4 def key @key end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
4 5 6 |
# File 'lib/carvoyant_api/resources/data_point.rb', line 4 def @timestamp end |
#translated_value ⇒ Object (readonly)
Returns the value of attribute translated_value.
4 5 6 |
# File 'lib/carvoyant_api/resources/data_point.rb', line 4 def translated_value @translated_value end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/carvoyant_api/resources/data_point.rb', line 4 def value @value end |
#waypoint ⇒ Object (readonly)
Returns the value of attribute waypoint.
4 5 6 |
# File 'lib/carvoyant_api/resources/data_point.rb', line 4 def waypoint @waypoint end |