Permalink
Browse files

Merge pull request #1 from GunioRobot/clean

Hi! I cleaned up your code for you!
  • Loading branch information...
jeffremer committed Dec 19, 2011
2 parents 1609e8b + 2bb4bb9 commit f9a1dc1cdb43561df3b8cb10ef837f8c81e7c3e0
Showing with 32 additions and 33 deletions.
  1. +2 −2 lib/muni/base.rb
  2. +2 −2 lib/muni/direction.rb
  3. +1 −1 lib/muni/prediction.rb
  4. +10 −10 lib/muni/route.rb
  5. +1 −1 man/muni.1.html
  6. +11 −12 man/muni.1.ronn
  7. +1 −1 muni.gemspec
  8. +2 −2 spec/route_spec.rb
  9. +2 −2 spec/stop_spec.rb
View
@@ -11,7 +11,7 @@ def fetch(command, options = nil)
fail NextBusError, doc['Error'].first['content'].gsub(/\n/,'') if doc['Error']
doc
end
-
+
def build_url(command, options = nil)
url = "http://webservices.nextbus.com/service/publicXMLFeed?command=%s&a=sf-muni" % command
if options
@@ -21,7 +21,7 @@ def build_url(command, options = nil)
end
url
end
-
+
end
end
end
View
@@ -4,10 +4,10 @@ module Muni
class Direction < Base
def stop_at(place)
return stops.select{|stop| stop.tag == place}.first if place =~ /[1-9][0-9]+/
- pattern = Amatch::Sellers.new(place)
+ pattern = Amatch::Sellers.new(place)
stops.sort_by{ |stop|
pattern.match(stop.title)
}.first
end
end
-end
+end
View
@@ -6,7 +6,7 @@ class Prediction < Base
def time
Time.at((epochTime.to_i / 1000.0).to_i)
end
-
+
def pretty_time
if time > Time.now
distance_of_time_in_words_to_now(time)
View
@@ -10,7 +10,7 @@ def direction_at(direction)
return send(direction.downcase.to_sym) if direction =~ /(outbound|inbound)/i
directions.select{|dir| dir.id == direction}.first
end
-
+
def outbound
directions.select{|dir| dir.name =~ /outbound/i}.first
end
@@ -24,41 +24,41 @@ def find(tag)
if tag == :all
find_all
else
- find_by_tag(tag)
+ find_by_tag(tag)
end
end
-
+
private
def find_all
document = fetch(:routeList)
document['route'].collect do |el|
Route.new(el)
end
end
-
+
def find_by_tag(tag)
document = fetch(:routeConfig, {:r => tag})
route = Route.new({:tag => document['route'].first['tag'], :title => document['route'].first['title']})
-
+
stops = {}
-
+
document['route'].first['stop'].each do |stop|
st = Stop.new({
:tag => stop['tag'],
:title => stop['title'],
:lat => stop['lat'],
:lon => stop['lat'],
- :stopId => stop['lat'],
+ :stopId => stop['lat'],
})
stops[st[:tag]] = st
end
-
+
directions = []
route.directions = document['route'].first['direction'].collect do |direction|
direction_stops = direction['stop'].collect do |stop|
stops[stop['tag']]
end
-
+
direction_stops.each do |stop|
stop.route_tag = route.tag
stop.direction = direction['tag']
@@ -70,7 +70,7 @@ def find_by_tag(tag)
:stops => direction_stops
})
end
-
+
route
end
end
View
@@ -157,7 +157,7 @@ <h2 id="EXAMPLES">EXAMPLES</h2>
<p>With a fuzzy direction and stop name:</p>
-<pre><code>$ muni predict 21 inbound hayes and shrader
+<pre><code>$ muni predict 21 inbound hayes and shrader
Route 21-Hayes going Inbound to Steuart Terminal at Hayes St &amp; Shrader St:
8102 less than a minute
2832 2 minutes
View
@@ -7,8 +7,8 @@ muni(1) -- show san francisco muni routes and stop predictions
`muni` `list`<br/>
`muni` `predict` <route> <direction> <stop><br/>
`muni` `show` `-v`|`--verbose` <route> [<direction>]<br/>
-
-## DESCRIPTION
+
+## DESCRIPTION
**muni** retrieves San Francisco MUNI routes information and bus stop prediction
times. `muni` is mostly an exercise in implementing the core functions of the `muni`
@@ -25,7 +25,7 @@ List all available routes:
L L-Taraval
M M-Ocean View
....
-
+
Show basic route information:
$ muni show 21
@@ -45,7 +45,7 @@ Show a route and all stops using `-v` or `--verbose`:
6501 Steuart St & Market St
5669 Market St & Drumm St
...
-
+
Show a route and all stops for a particular direction:
$ muni show 21 outbound --verbose
@@ -59,7 +59,7 @@ Show a route and all stops for a particular direction:
Get predictions for a bus, going a certain direction, at a given stop.
`predict` can take the formal tag names for the direction and stop, or
it will perform it's best guess.
-
+
With formal direction and stop tags:
$ muni predict 21 21_OB4 5008
@@ -71,7 +71,7 @@ With formal direction and stop tags:
2823 about 1 hour
With a fuzzy stop name:
-
+
$ muni predict 21 21_OB4 hayes and shrader
Route 21-Hayes going Outbound to Fulton St & Shrader St at Hayes St & Shrader St:
2831 2 minutes
@@ -81,15 +81,14 @@ With a fuzzy stop name:
2823 about 1 hour
With a fuzzy direction and stop name:
-
- $ muni predict 21 inbound hayes and shrader
+
+ $ muni predict 21 inbound hayes and shrader
Route 21-Hayes going Inbound to Steuart Terminal at Hayes St & Shrader St:
8102 less than a minute
2832 2 minutes
2831 22 minutes
8189 32 minutes
2842 about 1 hour
-
-
-
-
+
+
+
View
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
s.add_dependency "actionpack"
s.add_dependency "amatch"
# For the executable
- s.add_dependency "thor"
+ s.add_dependency "thor"
s.add_development_dependency "rspec", "~> 2.0.0.beta.22"
end
View
@@ -2,10 +2,10 @@
require 'muni/route'
describe "Muni::Route" do
- it "fetches all available routes" do
+ it "fetches all available routes" do
Muni::Route.find(:all)
end
-
+
it "fetches routes by tag" do
Muni::Route.find(21)
end
View
@@ -2,13 +2,13 @@
require 'muni/route'
describe "Muni::Stop" do
- it "#times fetches predictions" do
+ it "#times fetches predictions" do
route = Muni::Route.find(21)
direction = route.directions.first
stop = direction.stops.first
times = stop.predictions
times.each do |time|
p time.pretty_time
- end
+ end
end
end

0 comments on commit f9a1dc1

Please sign in to comment.