Module: DVB
- Defined in:
- lib/dvb.rb,
lib/dvb/find.rb,
lib/dvb/utils.rb,
lib/dvb/monitor.rb,
lib/dvb/version.rb
Defined Under Namespace
Classes: Departure, Stop, TransportMode
Constant Summary
collapse
- VERSION =
'1.1.0'
Class Method Summary
collapse
Class Method Details
.distance_between(lat1, lng1, lat2, lng2) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/dvb/utils.rb', line 74
def self.distance_between(lat1, lng1, lat2, lng2)
point1 = Geokit::LatLng.new(lat1, lng1)
point2 = Geokit::LatLng.new(lat2, lng2)
point1.distance_to(point2) * 1000
end
|
.find(search_str, region = 'Dresden') ⇒ Object
2
3
4
5
6
7
8
9
10
11
|
# File 'lib/dvb/find.rb', line 2
def self.find(search_str, region = 'Dresden')
all_stops = load_local_stops
all_stops.select do |stop|
search_str.downcase!
(stop.name.downcase.include?(search_str) || stop.search_str.downcase.include?(search_str)) && stop.region == region
end
end
|
.find_near(lat, lng, radius = 500) ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/dvb/find.rb', line 13
def self.find_near(lat, lng, radius = 500)
all_stops = load_local_stops.reject { |s| s.lat.nil? || s.lng.nil? }
all_stops.select do |stop|
DVB::distance_between(stop.lat, stop.lng, lat, lng) <= radius
end
end
|
.load_local_stops ⇒ Object
22
23
24
25
|
# File 'lib/dvb/find.rb', line 22
def self.load_local_stops
path = File.expand_path(File.dirname(__FILE__)) + '/VVOStops.json'
JSON.parse(File.read(path)).map { |e| DVB::Stop.with_str_hash(e) }
end
|
.monitor(stop, offset = 0, lim = 0, city = 'Dresden') ⇒ Object
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/dvb/monitor.rb', line 8
def self.monitor(stop, offset = 0, lim = 0, city = 'Dresden')
response = RestClient.get 'http://widgets.vvo-online.de/abfahrtsmonitor/Abfahrten.do',
{ params: {
ort: city,
hst: stop,
vz: offset,
lim: lim
}}
JSON.parse(response.to_str).map { |e| Departure.with_arr(e) }
end
|
.parse_mode(mode) ⇒ Object