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.
@@ -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
- usage
47
+ rescue => e
48
+ puts "Error: #{e}"
48
49
  end
49
50
 
50
51
  private
@@ -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? || Time.now.sunday?
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.saturday?
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
@@ -80,7 +80,7 @@ class Trip
80
80
  end
81
81
 
82
82
  def stops(dir=@direction)
83
- @stops ||= Schedule.abbrevs.select { |_, v| time_data.map_nth(3).any? { |d| d =~ /^#{v}/ } }.keys
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caltrain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.7.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: