Class: TTC::Route
- Inherits:
-
Object
- Object
- TTC::Route
- Defined in:
- lib/ttc-gps/models.rb
Overview
<route lonMin=‘-79.5444325’ title=‘501- Queen’ tag=‘501’ color=‘e92127’ latMax=‘43.6739102’ lonMax=‘-79.2817125’ oppositeColor=‘ffffff’ latMin=‘43.591831’>
Instance Attribute Summary collapse
-
#bounds ⇒ Object
Returns the value of attribute bounds.
-
#directions ⇒ Object
Returns the value of attribute directions.
-
#stop_map ⇒ Object
Returns the value of attribute stop_map.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #add_stop(stop) ⇒ Object
- #add_stop_to_direction(direction, stop_tag) ⇒ Object
- #contains?(latlon, radius = 0) ⇒ Boolean
- #get_closest_stop(latlon, direction) ⇒ Object
- #get_closest_stops(latlon, direction) ⇒ Object
-
#initialize ⇒ Route
constructor
A new instance of Route.
-
#to_json(*args) ⇒ Object
:tag, :title, :bounds, :stop_map, :directions.
Constructor Details
#initialize ⇒ Route
Returns a new instance of Route.
71 72 73 74 |
# File 'lib/ttc-gps/models.rb', line 71 def initialize @stop_map = {} @directions = {} end |
Instance Attribute Details
#bounds ⇒ Object
Returns the value of attribute bounds.
69 70 71 |
# File 'lib/ttc-gps/models.rb', line 69 def bounds @bounds end |
#directions ⇒ Object
Returns the value of attribute directions.
69 70 71 |
# File 'lib/ttc-gps/models.rb', line 69 def directions @directions end |
#stop_map ⇒ Object
Returns the value of attribute stop_map.
69 70 71 |
# File 'lib/ttc-gps/models.rb', line 69 def stop_map @stop_map end |
#tag ⇒ Object
Returns the value of attribute tag.
69 70 71 |
# File 'lib/ttc-gps/models.rb', line 69 def tag @tag end |
#title ⇒ Object
Returns the value of attribute title.
69 70 71 |
# File 'lib/ttc-gps/models.rb', line 69 def title @title end |
Class Method Details
.parse_element(element) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ttc-gps/models.rb', line 116 def Route.parse_element element attrs = element.attributes r = Route.new r.tag = attrs["tag"] r.title = attrs["title"] r.bounds = Geokit::Bounds.new( Geokit::LatLng.new(Float(attrs["latMin"]), Float(attrs["lonMin"])), Geokit::LatLng.new(Float(attrs["latMax"]), Float(attrs["lonMax"]))) r end |
Instance Method Details
#add_stop(stop) ⇒ Object
76 77 78 |
# File 'lib/ttc-gps/models.rb', line 76 def add_stop stop @stop_map[stop.tag] = stop end |
#add_stop_to_direction(direction, stop_tag) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ttc-gps/models.rb', line 80 def add_stop_to_direction direction, stop_tag if !@stop_map[stop_tag] puts "No stop found with tag, tag='#{stop_tag}'" return end dir_arr = @directions[direction] || [] dir_arr << @stop_map[stop_tag] @directions[direction] = dir_arr end |
#contains?(latlon, radius = 0) ⇒ Boolean
91 92 93 |
# File 'lib/ttc-gps/models.rb', line 91 def contains? latlon, radius=0 @bounds.contains? latlon end |
#get_closest_stop(latlon, direction) ⇒ Object
101 102 103 |
# File 'lib/ttc-gps/models.rb', line 101 def get_closest_stop latlon, direction get_closest_stops[0] end |
#get_closest_stops(latlon, direction) ⇒ Object
95 96 97 98 99 |
# File 'lib/ttc-gps/models.rb', line 95 def get_closest_stops latlon, direction @directions[direction].sort do |a, b| latlon.distance_to(a.position) <=> latlon.distance_to(b.position) end end |
#to_json(*args) ⇒ Object
:tag, :title, :bounds, :stop_map, :directions
107 108 109 110 111 112 113 114 |
# File 'lib/ttc-gps/models.rb', line 107 def to_json *args { 'tag' => @tag, 'title' => @title, 'bounds' => @bounds, 'directions' => @directions }.to_json(*args) end |