metra_schedule 0.2 → 0.2.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/metra/cacher.rb CHANGED
@@ -6,7 +6,7 @@ module MetraSchedule
6
6
  attr_accessor :cache_dir
7
7
 
8
8
  def initialize
9
- @cache_dir = "/home/#{ENV['USER']}/.metra_schedule"
9
+ @cache_dir = "#{ENV['HOME']}/.metra_schedule"
10
10
  end
11
11
 
12
12
  def self.load_from_cache(line)
data/lib/metra/line.rb CHANGED
@@ -93,7 +93,7 @@ module MetraSchedule
93
93
  unless start_or_destination == :start or start_or_destination == :destination
94
94
  raise ArgumentError.new "First argument must be either :start or :destination"
95
95
  end
96
- raise ArgumentError.new "Not a valid station" unless LINES[:up_nw][:stations].include?(station)
96
+ raise ArgumentError.new "Not a valid station" unless LINES[@line_key][:stations].include?(station)
97
97
  @start = station if start_or_destination == :start
98
98
  @destination = station if start_or_destination == :destination
99
99
  self
@@ -116,6 +116,12 @@ module MetraSchedule
116
116
  self
117
117
  end
118
118
 
119
+ def deduce_direction_by_time
120
+ @dir = :inbound if Time.now < Time.parse("12:00PM")
121
+ @dir = :outbound if Time.now > Time.parse("12:00PM")
122
+ self
123
+ end
124
+
119
125
  def trains
120
126
  return [] unless engines
121
127
  engines.find_all do |engine|
data/lib/metra/stop.rb CHANGED
@@ -14,5 +14,9 @@ module MetraSchedule
14
14
  @time > time
15
15
  end
16
16
 
17
+ def self.pretty_print(sym)
18
+ sym.to_s.split("_").map {|s| s.capitalize}.join("\s")
19
+ end
20
+
17
21
  end
18
22
  end
data/lib/metra/train.rb CHANGED
@@ -22,5 +22,11 @@ module MetraSchedule
22
22
  false
23
23
  end
24
24
 
25
+ def departure_and_arrival(start, destination)
26
+ departure = @stops.find {|s| s.station == start}.time
27
+ arrival = @stops.find {|s| s.station == destination}.time
28
+ {:departure => departure, :arrival => arrival}
29
+ end
30
+
25
31
  end
26
32
  end
data/test/test_line.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'test/unit'
2
2
  require File.join(File.dirname(__FILE__), "../lib", "metra")
3
+ require File.join(File.dirname(__FILE__), "timecop", "lib", "timecop")
3
4
 
4
5
  class TestLine < Test::Unit::TestCase
5
6
 
@@ -250,4 +251,15 @@ class TestLine < Test::Unit::TestCase
250
251
  assert_equal([train1, train2, train3, train4], line.trains)
251
252
  end
252
253
 
254
+
255
+ def test_deduce_direction_by_time
256
+ Timecop.freeze(Time.parse("11:00AM"))
257
+ line = Metra.new.line(:up_nw).deduce_direction_by_time
258
+ assert_equal(:inbound, line.dir)
259
+
260
+ Timecop.freeze(Time.parse("12:01PM"))
261
+ line = Metra.new.line(:up_nw).deduce_direction_by_time
262
+ assert_equal(:outbound, line.dir)
263
+ end
264
+
253
265
  end
data/test/test_stop.rb CHANGED
@@ -28,5 +28,9 @@ class TestLine < Test::Unit::TestCase
28
28
  assert(stop2.is_after?(Time.parse("12:35")))
29
29
  end
30
30
 
31
+ def test_pretty_print
32
+ assert_equal("Chicago Station", MetraSchedule::Stop.pretty_print(:chicago_station))
33
+ end
34
+
31
35
 
32
36
  end
data/test/test_train.rb CHANGED
@@ -51,4 +51,15 @@ class TestLine < Test::Unit::TestCase
51
51
  assert_equal(false, @@t.in_time?(:barrington, Time.parse("12:35")))
52
52
  end
53
53
 
54
+ def test_departure_and_arrival
55
+ stop1 = MetraSchedule::Stop.new :station => :barrington, :time => Time.parse("12:30")
56
+ stop2 = MetraSchedule::Stop.new :station => :arlington_heights, :time => Time.parse("12:40")
57
+ @@t = MetraSchedule::Train.new :train_num => 651, :bike_limit => 12, :schedule => :weekday, :direction => :inbound, :stops => [stop1, stop2]
58
+
59
+ l = Metra.new.line(:up_nw)
60
+ l.engines = [@@t]
61
+ train = l.trains.first
62
+ assert_equal({:departure => Time.parse("12:30"), :arrival => Time.parse("12:40")}, train.departure_and_arrival(:barrington, :arlington_heights))
63
+ end
64
+
54
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metra_schedule
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Smith