Module: OCTranspo::MobileRouteData
Instance Method Summary
collapse
#date_stamp, #default_options, #site
#cache, #cache_path, #cache_path_for, #create_fixture, #fixture_path_for, #fixtures_path, #logger, #read, #read_from_cache, #read_from_fixture, #read_from_remote, #reset!, #site, #use_fixtures!
Instance Method Details
#decode(source_code) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/octranspo/mobile_route_data.rb', line 73
def decode (source_code)
document = interpret(source_code)
if table_of_stops = document.at("#SchedulesStopListStopsTable")
direction = extract_route_and_direction_from(table_of_stops.search(:td)[1].inner_text)
direction[:direction_index] = document.at("#direction")[:value].sub('Direction', '')
direction[:stops] = table_of_stops.search("td.checkbox").map do |cell|
(cell.inner_text.strip)
end
return direction
end
end
|
#find(route_name_or_number, options = {}) ⇒ Object
Returns an array of direction hashes or nil if the route was not found.
41
42
43
44
45
46
47
|
# File 'lib/octranspo/mobile_route_data.rb', line 41
def find (route_name_or_number, options={})
options[:route] = route_name_or_number
directions = find_all_directions(options)
if directions.any?
return directions
end
end
|
#find_all_directions(options = {}) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/octranspo/mobile_route_data.rb', line 49
def find_all_directions (options={})
directions = []
0.upto(1) do |index|
directions << find_one_direction(options.merge(:index => index))
end
directions.compact
end
|
#find_one_direction(options = {}) ⇒ Object
57
58
59
|
# File 'lib/octranspo/mobile_route_data.rb', line 57
def find_one_direction (options={})
decode(read(options))
end
|
#path_for(options = {}) ⇒ Object
68
69
70
71
|
# File 'lib/octranspo/mobile_route_data.rb', line 68
def path_for (options={})
options = default_options.merge(options)
"#{date_stamp(options[:date])}/route_#{options[:route]}_index_#{options[:index]}.html"
end
|
#url_for(options = {}) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/octranspo/mobile_route_data.rb', line 61
def url_for (options={})
options = default_options.merge(options)
url = "#{site}/jnot/post.routelist.schedules.oci?"
url << "rangeIndex=5&day=#{date_stamp(options[:date])}"
url << "&route=#{options[:route]}&routeIndex=#{options[:index]}"
end
|