Class: TTC::Route

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRoute

Returns a new instance of Route.



70
71
72
73
# File 'lib/ttc-gps/models.rb', line 70

def initialize
  @stop_map = {}
  @directions = {}
end

Instance Attribute Details

#boundsObject

Returns the value of attribute bounds.



68
69
70
# File 'lib/ttc-gps/models.rb', line 68

def bounds
  @bounds
end

#directionsObject

Returns the value of attribute directions.



68
69
70
# File 'lib/ttc-gps/models.rb', line 68

def directions
  @directions
end

#stop_mapObject

Returns the value of attribute stop_map.



68
69
70
# File 'lib/ttc-gps/models.rb', line 68

def stop_map
  @stop_map
end

#tagObject

Returns the value of attribute tag.



68
69
70
# File 'lib/ttc-gps/models.rb', line 68

def tag
  @tag
end

#titleObject

Returns the value of attribute title.



68
69
70
# File 'lib/ttc-gps/models.rb', line 68

def title
  @title
end

Class Method Details

.parse_element(element) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/ttc-gps/models.rb', line 115

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



75
76
77
# File 'lib/ttc-gps/models.rb', line 75

def add_stop stop
  @stop_map[stop.tag] = stop
end

#add_stop_to_direction(direction, stop_tag) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/ttc-gps/models.rb', line 79

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

Returns:

  • (Boolean)


90
91
92
# File 'lib/ttc-gps/models.rb', line 90

def contains? latlon, radius=0
  @bounds.contains? latlon
end

#get_closest_stop(latlon, direction) ⇒ Object



100
101
102
# File 'lib/ttc-gps/models.rb', line 100

def get_closest_stop latlon, direction
  get_closest_stops[0]
end

#get_closest_stops(latlon, direction) ⇒ Object



94
95
96
97
98
# File 'lib/ttc-gps/models.rb', line 94

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



106
107
108
109
110
111
112
113
# File 'lib/ttc-gps/models.rb', line 106

def to_json *args
  {
    'tag' => @tag,
    'title' => @title,
    'bounds' => @bounds,
    'directions' => @directions
  }.to_json(*args)
end