russianpost 0.4.5 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da46adf9f7207d98af2037c0c12d26d3ecff2803
4
- data.tar.gz: f2397fb606ad100130ac6093e2b6eb06795de8de
3
+ metadata.gz: b6585900413a5e00bb43ef2b5704a24d5a1772a5
4
+ data.tar.gz: 81ffcfe46db8a248952f105faf04c7eea1826c74
5
5
  SHA512:
6
- metadata.gz: 0495a81e24f4b0a8f59bbc32680b3c623c4b398fa44b3d8e6f0c5fd5da17213b8e9244340c55dfd7f6353810126bf1b6e26bfadb3e8c088cbe20b6d8fedd8c4c
7
- data.tar.gz: 1328b97674bf01ef7d05e2ccf5a3894a833539db7225362eb7308f0324fece819f8a53c128de0b2ae51aec7c37e1e7f3220650adfc954ddb00536ed06493b7ea
6
+ metadata.gz: 8f5d467ab436e2b4c6cbec9dbfcab2ddfc2449c35595c593f5a2b09627043162e585b697595e1419b7bb5939a8e307de57a87c75b70be03ffd5898b767e5c242
7
+ data.tar.gz: d081eb9c72d536414a43a16bf351f494dc2c69722659f34eece265bf15bb582062fdf4ee2fc48588b2e7077506ce3520a8c141fc07b6247f29ff4438089b1e96
data/README.md CHANGED
@@ -14,7 +14,7 @@ To install gem stand-alone:
14
14
 
15
15
  To use gem in a Rails app, add the following to your `Gemfile`:
16
16
 
17
- gem "russianpost", "~> 0.4.5"
17
+ gem "russianpost", "~> 0.5.0"
18
18
 
19
19
  This gem uses [Savon](http://savonrb.com/), which in turn uses [HTTPI](https://github.com/savonrb/httpi) internally. HTTPI chooses the best HTTP library of those you have installed. For the fastest results, make sure you add [Curb](https://github.com/taf2/curb) to your `Gemfile`:
20
20
 
@@ -11,23 +11,14 @@ module RussianPost
11
11
 
12
12
  def initialize(barcode)
13
13
  @barcode = barcode.strip.upcase
14
- raise InvalidBarcode unless valid?
15
14
  end
16
15
 
17
16
  def to_s
18
17
  barcode
19
18
  end
20
19
 
21
- def digits
22
- barcode[/\d+/].split("").map { |d| d.to_i }
23
- end
24
-
25
- private
26
-
27
20
  def valid?
28
- BarcodeValidator.validate(self)
21
+ BarcodeValidator.validate(barcode)
29
22
  end
30
23
  end
31
-
32
- class InvalidBarcode < ArgumentError; end
33
24
  end
@@ -12,7 +12,7 @@ module RussianPost
12
12
 
13
13
  def initialize(barcode)
14
14
  @barcode = barcode
15
- @digits = barcode.digits
15
+ @digits = barcode[/\d+/].split("").map { |d| d.to_i }
16
16
  end
17
17
 
18
18
  def valid?
@@ -23,11 +23,11 @@ module RussianPost
23
23
  private
24
24
 
25
25
  def valid_international?
26
- barcode =~ INTERNATIONAL_FORMAT && digits.last == checkdigit
26
+ (barcode =~ INTERNATIONAL_FORMAT && digits.last == checkdigit) || false
27
27
  end
28
28
 
29
29
  def valid_domestic?
30
- barcode =~ DOMESTIC_FORMAT
30
+ barcode =~ DOMESTIC_FORMAT || false
31
31
  end
32
32
 
33
33
  def checkdigit
@@ -38,7 +38,10 @@ module RussianPost
38
38
  private
39
39
 
40
40
  def fetch_operations
41
+ raise InvalidBarcode unless barcode.valid?
41
42
  OperationsFactory.build(client.call(barcode: barcode))
42
43
  end
43
44
  end
45
+
46
+ class InvalidBarcode < ArgumentError; end
44
47
  end
@@ -1,3 +1,3 @@
1
1
  module Russianpost
2
- VERSION = "0.4.5"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -8,17 +8,13 @@ module RussianPost
8
8
  assert_equal "bar RD025500807SE", "bar #{barcode}"
9
9
  end
10
10
 
11
- def test_raises_on_invalid_barcode
11
+ def test_validates_barcode
12
12
  ["123", "RR123456789EE"].each do |barcode|
13
- assert_raises InvalidBarcode do
14
- Barcode.new(barcode)
15
- end
13
+ refute Barcode.new(barcode).valid?
16
14
  end
17
- end
18
15
 
19
- def test_doesnt_raise_on_valid_barcode
20
16
  ["RD025500807SE", "12345678901234"].each do |barcode|
21
- Barcode.new(barcode)
17
+ assert Barcode.new(barcode).valid?
22
18
  end
23
19
  end
24
20
  end
@@ -23,7 +23,7 @@ module RussianPost
23
23
 
24
24
  def test_raises_error_on_invalid_barcode
25
25
  assert_raises InvalidBarcode do
26
- Parcel.new("123")
26
+ Parcel.new("123").operations
27
27
  end
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: russianpost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Shitov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-07 00:00:00.000000000 Z
11
+ date: 2013-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler