Skip to content

Commit

Permalink
also get north and south bound routes
Browse files Browse the repository at this point in the history
  • Loading branch information
hayeah committed Oct 10, 2010
1 parent 29077b2 commit 8358251
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Rakefile
Expand Up @@ -8,6 +8,7 @@ Twink::Application.load_tasks

namespace :translink do
task :update => :environment do
Route.populate
n = ENV["n"] && ENV["n"].to_i
Route.populate(n)
end
end
11 changes: 7 additions & 4 deletions app/models/route.rb
@@ -1,15 +1,18 @@
require 'translink'
class Route < ActiveRecord::Base
has_many :stops
def self.populate
def self.populate(n=nil)
api = Translink.new
Route.transaction do
Route.delete_all
Stop.delete_all
api.routes.each do |route|
p route.name
routes = api.routes
if n
routes = routes[0..n]
end
routes.each do |route|
record = Route.create(:uid => route.id,:name => route.name)
(route.west + route.east).each do |stop|
(route.west + route.east + route.north + route.south).each do |stop|
p stop.name
record.stops.create(:uid => stop.id,
:name => stop.name,
Expand Down
8 changes: 8 additions & 0 deletions lib/translink.rb
Expand Up @@ -71,6 +71,14 @@ def east
@east ||= stops("East")
end

def north
@east ||= stops("North")
end

def south
@east ||= stops("South")
end

def to_json
{ "id" => id,
"name" => name,
Expand Down

0 comments on commit 8358251

Please sign in to comment.