Class: CarvoyantAPI::DataPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/carvoyant_api/resources/data_point.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/carvoyant_api/resources/data_point.rb', line 4

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/carvoyant_api/resources/data_point.rb', line 4

def key
  @key
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



4
5
6
# File 'lib/carvoyant_api/resources/data_point.rb', line 4

def timestamp
  @timestamp
end

#translated_valueObject (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

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/carvoyant_api/resources/data_point.rb', line 4

def value
  @value
end

#waypointObject (readonly)

Returns the value of attribute waypoint.



4
5
6
# File 'lib/carvoyant_api/resources/data_point.rb', line 4

def waypoint
  @waypoint
end