Module: Caltrain
- Extended by:
- Printing
- Defined in:
- lib/caltrain.rb
Class Method Summary
collapse
Methods included from Printing
pretty_hash, print_trip, stop_info, train_info
Class Method Details
.base_dir ⇒ Object
12
13
14
|
# File 'lib/caltrain.rb', line 12
def base_dir
File.expand_path('..', File.dirname(__FILE__))
end
|
.clean! ⇒ Object
25
26
27
28
29
30
|
# File 'lib/caltrain.rb', line 25
def clean!
[self, Trip].each do |klass|
klass.instance_variables.each { |i| klass.instance_variable_set(i, nil) }
end
true
end
|
.run!(args) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/caltrain.rb', line 32
def run!(args)
loc, dir, act = *args
usage unless loc && dir
loc = loc.to_sym
act = :next unless act
detailed = args.include?('--stops')
populate_trips!
if dir =~ /^n/i
Schedule.method(act).call(loc, :north, $stdout, detailed)
elsif dir =~ /^s/i
Schedule.method(act).call(loc, :south, $stdout, detailed)
else
raise("#{dir} is not a recognized direction")
end
rescue => e
puts "Error: #{e}"
end
|
.usage ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/caltrain.rb', line 16
def usage
puts "Usage:"
puts " caltrain <location> <direction> [ list | next ] [ --stops ]"
puts ""
puts "Abbreviations:"
pretty_hash(Schedule.abbrevs)
exit(1)
end
|