caltrain 0.0.7 → 0.0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/caltrain.rb +4 -3
- data/lib/caltrain/schedule.rb +16 -2
- data/lib/caltrain/trip.rb +1 -1
- metadata +1 -1
data/lib/caltrain.rb
CHANGED
@@ -31,6 +31,7 @@ module Caltrain
|
|
31
31
|
|
32
32
|
def run!(args)
|
33
33
|
loc, dir, act = *args
|
34
|
+
usage unless loc && dir
|
34
35
|
loc = loc.to_sym
|
35
36
|
act = :next unless act
|
36
37
|
|
@@ -41,10 +42,10 @@ module Caltrain
|
|
41
42
|
elsif dir =~ /^s/i
|
42
43
|
Schedule.method(act).call(loc, :south)
|
43
44
|
else
|
44
|
-
raise
|
45
|
+
raise("#{dir} is not a recognized direction")
|
45
46
|
end
|
46
|
-
rescue
|
47
|
-
|
47
|
+
rescue => e
|
48
|
+
puts "Error: #{e}"
|
48
49
|
end
|
49
50
|
|
50
51
|
private
|
data/lib/caltrain/schedule.rb
CHANGED
@@ -19,6 +19,7 @@ module Schedule
|
|
19
19
|
|
20
20
|
def next(loc, dir, output=$stdout)
|
21
21
|
trip = trips_with_times(loc, dir).find { |_, time| time > now }
|
22
|
+
raise("No trips found!") unless trip
|
22
23
|
options = {:output => output, :starting_at => loc}
|
23
24
|
|
24
25
|
print_trip(trip.first, trip.last, options)
|
@@ -47,11 +48,15 @@ module Schedule
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def weekend?
|
50
|
-
saturday? ||
|
51
|
+
saturday? || sunday?
|
52
|
+
end
|
53
|
+
|
54
|
+
def sunday?
|
55
|
+
Time.now.strftime("%A") == "Sunday"
|
51
56
|
end
|
52
57
|
|
53
58
|
def saturday?
|
54
|
-
Time.now.
|
59
|
+
Time.now.strftime("%A") == "Saturday"
|
55
60
|
end
|
56
61
|
|
57
62
|
def abbrevs
|
@@ -89,5 +94,14 @@ module Schedule
|
|
89
94
|
:sf => "San Francisco"
|
90
95
|
}.freeze
|
91
96
|
end
|
97
|
+
|
98
|
+
# for 1.8 support :/
|
99
|
+
def stop_order
|
100
|
+
@stop_order ||= [
|
101
|
+
:gil, :smt, :mrg, :bhl, :cap, :tam, :sj, :clp, :sc, :law, :sv,
|
102
|
+
:mv, :sa, :cal, :pa, :men, :ath, :rc, :scl, :bel, :hil, :hay, :sm,
|
103
|
+
:brl, :bdw, :mil, :sb, :ssf, :bsh, :tt, :sf
|
104
|
+
].freeze
|
105
|
+
end
|
92
106
|
end
|
93
107
|
end
|
data/lib/caltrain/trip.rb
CHANGED
@@ -80,7 +80,7 @@ class Trip
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def stops(dir=@direction)
|
83
|
-
@stops ||= Schedule.
|
83
|
+
@stops ||= Schedule.stop_order.select { |stop| time_data.map_nth(3).any? { |d| d =~ /^#{Schedule.abbrevs[stop]}/ } }
|
84
84
|
dir == :north ? @stops : @stops.reverse
|
85
85
|
end
|
86
86
|
end
|