Class: AxTrack::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/ax_track/objects/tracker.rb,
lib/ax_track/objects/tracker/gps_position.rb

Defined Under Namespace

Classes: GPSPosition

Instance Method Summary collapse

Methods inherited from Object

#create_getters, #initialize

Constructor Details

This class inherits a constructor from AxTrack::Object

Instance Method Details

#asset_detailsObject



4
5
6
7
# File 'lib/ax_track/objects/tracker.rb', line 4

def asset_details
  @asset_details = Asset.new @asset_details unless @asset_details.is_a? Asset
  @asset_details
end

#asset_idObject



9
10
11
# File 'lib/ax_track/objects/tracker.rb', line 9

def asset_id
  asset_details.id
end

#available_sensor_dataObject



38
39
40
41
42
43
44
45
# File 'lib/ax_track/objects/tracker.rb', line 38

def available_sensor_data
  # returns a hash with available senson data
  sensor_data_temp = self.sensor_data.keys
  # if no timestamp is available in the GPSPosition, then there wasn't a last_gps_measurement returned in the json
  # hence the sensor doesn't contain a GPS module.
  sensor_data_temp = sensor_data_temp.unshift('gps') if self.last_gps_position&.respond_to? :timestamp
  sensor_data_temp
end

#batteryObject



26
27
28
# File 'lib/ax_track/objects/tracker.rb', line 26

def battery
  asset_details&.sensor_data.dig('battery', 'value')
end

#last_gps_positionObject



21
22
23
24
# File 'lib/ax_track/objects/tracker.rb', line 21

def last_gps_position
  #GPSPosition.new(@last_gps_measurement || { lat: asset_details.lat, lng: asset_details.lng } )
  GPSPosition.new(@last_gps_measurement) unless @last_gps_measurement.nil?
end

#last_message_timestampObject



17
18
19
# File 'lib/ax_track/objects/tracker.rb', line 17

def last_message_timestamp
  DateTime.parse(@last_message_timestamp, false) if @last_message_timestamp
end

#nameObject



13
14
15
# File 'lib/ax_track/objects/tracker.rb', line 13

def name
  @name ||= asset_details.name
end

#sensor_dataObject



30
31
32
# File 'lib/ax_track/objects/tracker.rb', line 30

def sensor_data
  asset_details.sensor_data
end

#website_urlObject



34
35
36
# File 'lib/ax_track/objects/tracker.rb', line 34

def website_url
  "#{AxTrack.base_url_user}#{@id}"
end