Class: TTC::Vehicle

Inherits:
Object
  • Object
show all
Defined in:
lib/ttc-gps/models.rb

Overview

<vehicle lon=‘-79.3582’ secsSinceReport=‘7’ predictable=‘true’ speedKmHr=‘0.0’ dirTag=‘504_westbound’ id=‘4142’ heading=‘54’ lat=‘43.677082’ routeTag=‘504’/>

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dirObject

Returns the value of attribute dir.



37
38
39
# File 'lib/ttc-gps/models.rb', line 37

def dir
  @dir
end

#headingObject

Returns the value of attribute heading.



37
38
39
# File 'lib/ttc-gps/models.rb', line 37

def heading
  @heading
end

#idObject

Returns the value of attribute id.



37
38
39
# File 'lib/ttc-gps/models.rb', line 37

def id
  @id
end

#positionObject

Returns the value of attribute position.



37
38
39
# File 'lib/ttc-gps/models.rb', line 37

def position
  @position
end

#predictableObject

Returns the value of attribute predictable.



37
38
39
# File 'lib/ttc-gps/models.rb', line 37

def predictable
  @predictable
end

#routeObject

Returns the value of attribute route.



37
38
39
# File 'lib/ttc-gps/models.rb', line 37

def route
  @route
end

#routeIdObject

Returns the value of attribute routeId.



37
38
39
# File 'lib/ttc-gps/models.rb', line 37

def routeId
  @routeId
end

#secs_since_reportObject

Returns the value of attribute secs_since_report.



37
38
39
# File 'lib/ttc-gps/models.rb', line 37

def secs_since_report
  @secs_since_report
end

#tsObject

Returns the value of attribute ts.



37
38
39
# File 'lib/ttc-gps/models.rb', line 37

def ts
  @ts
end

Class Method Details

.parse_element(element) ⇒ Object

Parses an XML element into a Vehicle instance



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ttc-gps/models.rb', line 51

def Vehicle.parse_element element
  attrs = element.attributes

  v = Vehicle.new
  v.id = attrs["id"]
  v.route = attrs["routeTag"]
  v.position = Geokit::LatLng.new(Float(attrs["lat"]), Float(attrs["lon"]))      
  v.heading = Float(attrs["heading"])
  v.dir = attrs["dirTag"]
  v.secs_since_report = Integer(attrs["secsSinceReport"])
  v.predictable = Boolean(attrs["predictable"])
  v    
end

Instance Method Details

#to_json(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/ttc-gps/models.rb', line 39

def to_json *args
  {
    'id' => @id,
    'routeId' => @routeId,
    'position' => @position,
    'heading' => @heading,
    'dir' => @dir,
    'ts' => @ts
  }.to_json(*args)
end