Skip to content
Browse files

Match stops without a locality.

  • Loading branch information...
1 parent 7b8233e commit 2d6623a3710d3c15de7f3563156a1c7c40462aef @tatey committed Mar 15, 2012
Showing with 24 additions and 1 deletion.
  1. +12 −1 lib/translink/model/stop/extractor.rb
  2. +12 −0 test/translink/model/stop/extractor_test.rb
View
13 lib/translink/model/stop/extractor.rb
@@ -1,6 +1,16 @@
module Translink
module Model
class Stop::Extractor
+ module Nil
+ def gsub *args
+ self
+ end
+
+ def strip
+ self
+ end
+ end
+
REGEXES = {
/[\s\(]opposite approaching/i => 'opposite_approaching',
/[\s\(]opposite far side of/i => 'opposite_far_side',
@@ -45,7 +55,8 @@ def regex
end
def segments
- summary_or_name.split regex
+ results = summary_or_name.split regex
+ results.size == 2 ? results : [summary_or_name, nil.extend(Nil)]
end
def summary_or_name
View
12 test/translink/model/stop/extractor_test.rb
@@ -97,4 +97,16 @@ def test_street2_near
def test_locality_near
assert_equal 'near', stub_extractor(:summary => 'Allamanda, Old Northern Rd (Near Allamanda Cres)').locality
end
+
+ def test_street1_without_locality
+ assert_equal 'Oyster Cove - Hail And Ride', stub_extractor(:name => 'Oyster Cove - Hail And Ride').street1
+ end
+
+ def test_street2_without_locality
+ assert_nil stub_extractor(:name => 'Oyster Cove - Hail And Ride').street2
+ end
+
+ def test_locality_without_locality
+ assert_nil stub_extractor(:name => 'Oyster Cove - Hail And Ride').locality
+ end
end

0 comments on commit 2d6623a

Please sign in to comment.
Something went wrong with that request. Please try again.