stalkr 0.9.4 → 0.9.5

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4
1
+ 0.9.5
@@ -11,6 +11,7 @@ require 'date'
11
11
 
12
12
 
13
13
  stalkr_dir = File.dirname(__FILE__)
14
+ require "#{stalkr_dir}/stalkr/datetime_patch"
14
15
  require "#{stalkr_dir}/stalkr/base"
15
16
  require "#{stalkr_dir}/stalkr/result"
16
17
  require "#{stalkr_dir}/stalkr/error"
@@ -21,37 +22,5 @@ require "#{stalkr_dir}/stalkr/fedex"
21
22
  require "#{stalkr_dir}/stalkr/dhl"
22
23
  require "#{stalkr_dir}/stalkr/china_post"
23
24
 
24
- if not DateTime.new.public_methods.include? "to_time" then
25
- # monkey patch DateTime to add to_time (exists in Ruby 1.9.2 and above)
26
- class DateTime
27
- def to_time
28
- d = new_offset(0)
29
- t = d.instance_eval do
30
- Time.utc(year, mon, mday, hour, min, sec +
31
- sec_fraction)
32
- end
33
- t.getlocal
34
- end
35
- end
36
- end
37
25
 
38
- module Stalkr
39
-
40
- def self.shippers
41
- return [ Stalkr::UPS, Stalkr::USPS, Stalkr::FEDEX ]
42
- end
43
-
44
- def self.track(id)
45
- shipper = nil
46
- if id =~ /\d{22}/ then
47
- shipper = Stalkr::USPS
48
- elsif id =~ /^1Z/ then
49
- shipper = Stalkr::UPS
50
- elsif id =~ /\d{20}/ or id =~ /\d{15}/ then
51
- shipper = Stalkr::FEDEX
52
- end
53
- raise 'Unknown shipper code' if shipper.nil?
54
- return shipper.new.track(id)
55
- end
56
-
57
- end # module Stalkr
26
+
@@ -1,6 +1,20 @@
1
1
 
2
2
  module Stalkr
3
3
 
4
+ @@shippers = []
5
+
6
+ def self.shippers
7
+ return @@shippers
8
+ end
9
+
10
+ def self.detect_shipper(text)
11
+ Stalkr.shippers.each do |s|
12
+ id = s.extract_id(text)
13
+ return [id, s] if id
14
+ end
15
+ return nil
16
+ end
17
+
4
18
  class Base
5
19
 
6
20
  class << self
@@ -65,3 +65,5 @@ class ChinaPost < Base
65
65
 
66
66
  end # class ChinaPost
67
67
  end # module Stalkr
68
+
69
+ Stalkr.shippers << Stalkr::ChinaPost
@@ -0,0 +1,14 @@
1
+
2
+ if not DateTime.new.public_methods.include? "to_time" then
3
+ # monkey patch DateTime to add to_time (exists in Ruby 1.9.2 and above)
4
+ class DateTime
5
+ def to_time
6
+ d = new_offset(0)
7
+ t = d.instance_eval do
8
+ Time.utc(year, mon, mday, hour, min, sec +
9
+ sec_fraction)
10
+ end
11
+ t.getlocal
12
+ end
13
+ end
14
+ end
@@ -70,3 +70,5 @@ class DHL < Base
70
70
 
71
71
  end # class ChinaPost
72
72
  end # module Stalkr
73
+
74
+ Stalkr.shippers << Stalkr::DHL
@@ -77,3 +77,5 @@ class FEDEX < Base
77
77
 
78
78
  end # class FEDEX
79
79
  end # module Stalkr
80
+
81
+ Stalkr.shippers << Stalkr::FEDEX
@@ -86,3 +86,5 @@ class UPS < Base
86
86
 
87
87
  end # class UPS
88
88
  end # module Stalkr
89
+
90
+ Stalkr.shippers << Stalkr::UPS
@@ -93,3 +93,5 @@ class USPS < Base
93
93
 
94
94
  end # class USPS
95
95
  end # module Stalkr
96
+
97
+ Stalkr.shippers << Stalkr::USPS
@@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
3
  class ChinaPost_Test < Test::Unit::TestCase
4
4
 
5
+ def test_has_shipper
6
+ assert(Stalkr.shippers.include? Stalkr::ChinaPost)
7
+ end
8
+
5
9
  def test_track
6
10
  id = "RA103044224CN"
7
11
  info = Stalkr::ChinaPost.new.track(id)
@@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
3
  class DHL_Test < Test::Unit::TestCase
4
4
 
5
+ def test_has_shipper
6
+ assert(Stalkr.shippers.include? Stalkr::DHL)
7
+ end
8
+
5
9
  def test_track
6
10
  id = "5391587692"
7
11
  info = Stalkr::DHL.new.track(id)
@@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
3
  class FEDEX_Test < Test::Unit::TestCase
4
4
 
5
+ def test_has_shipper
6
+ assert(Stalkr.shippers.include? Stalkr::FEDEX)
7
+ end
8
+
5
9
  def test_track
6
10
  id = "106050761498748"
7
11
  info = Stalkr::FEDEX.new.track(id)
@@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
3
  class UPS_Test < Test::Unit::TestCase
4
4
 
5
+ def test_has_shipper
6
+ assert(Stalkr.shippers.include? Stalkr::UPS)
7
+ end
8
+
5
9
  def test_track
6
10
  id = "1ZX799470341200708"
7
11
  info = Stalkr::UPS.new.track(id)
@@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
3
  class USPS_Test < Test::Unit::TestCase
4
4
 
5
+ def test_has_shipper
6
+ assert(Stalkr.shippers.include? Stalkr::USPS)
7
+ end
8
+
5
9
  def test_track
6
10
  id = "9400110200793331353367"
7
11
  info = Stalkr::USPS.new.track(id)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stalkr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 51
4
+ hash: 49
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 4
10
- version: 0.9.4
9
+ - 5
10
+ version: 0.9.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chetan Sarva
@@ -112,6 +112,7 @@ files:
112
112
  - lib/stalkr.rb
113
113
  - lib/stalkr/base.rb
114
114
  - lib/stalkr/china_post.rb
115
+ - lib/stalkr/datetime_patch.rb
115
116
  - lib/stalkr/dhl.rb
116
117
  - lib/stalkr/error.rb
117
118
  - lib/stalkr/fedex.rb