Module: OCTranspo::Stop
Instance Method Summary collapse
- #all ⇒ Object
- #find_all_by_name(name) ⇒ Object
- #find_all_by_number(number) ⇒ Object
- #find_all_matching(pattern) ⇒ Object
- #find_by_name(name) ⇒ Object
- #find_by_number(number) ⇒ Object
- #find_by_stop_id(stop_id) ⇒ Object
- #storage ⇒ Object
- #update ⇒ Object
Instance Method Details
#all ⇒ Object
7 8 9 |
# File 'lib/octranspo/stop.rb', line 7 def all @stops ||= YAML.load_file(storage) end |
#find_all_by_name(name) ⇒ Object
38 39 40 41 42 |
# File 'lib/octranspo/stop.rb', line 38 def find_all_by_name (name) all.select do |stop| stop[:name] == name end end |
#find_all_by_number(number) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/octranspo/stop.rb', line 25 def find_all_by_number (number) number = number.to_s all.select do |stop| stop[:number] == number end end |
#find_all_matching(pattern) ⇒ Object
44 45 46 47 48 |
# File 'lib/octranspo/stop.rb', line 44 def find_all_matching (pattern) all.select do |stop| pattern.match(stop[:name]) end end |
#find_by_name(name) ⇒ Object
32 33 34 35 36 |
# File 'lib/octranspo/stop.rb', line 32 def find_by_name (name) all.detect do |stop| stop[:name] == name end end |
#find_by_number(number) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/octranspo/stop.rb', line 18 def find_by_number (number) number = number.to_s all.detect do |stop| stop[:number] == number end end |
#find_by_stop_id(stop_id) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/octranspo/stop.rb', line 11 def find_by_stop_id (stop_id) stop_id = stop_id.to_s all.detect do |stop| stop[:stop_id] == stop_id end end |
#storage ⇒ Object
65 66 67 |
# File 'lib/octranspo/stop.rb', line 65 def storage "#{File.dirname(__FILE__)}/stops.yml" end |
#update ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/octranspo/stop.rb', line 50 def update url = "http://www.octranspo1.com/google/retrieve_stops?zoom=15" doc = Hpricot.XML(open(url).read) new_stops = (doc / :marker).map do |marker| attributes = {}.merge(marker.attributes).symbolize_keys attributes[:stop_id] = attributes.delete(:stopid) attributes[:number] = attributes.delete(:id).rjust(4, "0") attributes[:number] = nil if attributes[:number] == "0000" attributes end File.open(storage, 'w') { |f| f << YAML.dump(new_stops) } @stops = nil return all end |