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 +4 -4
- data/README.md +1 -1
- data/lib/russianpost/barcode.rb +1 -10
- data/lib/russianpost/barcode_validator.rb +3 -3
- data/lib/russianpost/parcel.rb +3 -0
- data/lib/russianpost/version.rb +1 -1
- data/test/russianpost/barcode_test.rb +3 -7
- data/test/russianpost/parcel_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6585900413a5e00bb43ef2b5704a24d5a1772a5
|
4
|
+
data.tar.gz: 81ffcfe46db8a248952f105faf04c7eea1826c74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
|
data/lib/russianpost/barcode.rb
CHANGED
@@ -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(
|
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.
|
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
|
data/lib/russianpost/parcel.rb
CHANGED
data/lib/russianpost/version.rb
CHANGED
@@ -8,17 +8,13 @@ module RussianPost
|
|
8
8
|
assert_equal "bar RD025500807SE", "bar #{barcode}"
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def test_validates_barcode
|
12
12
|
["123", "RR123456789EE"].each do |barcode|
|
13
|
-
|
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
|
-
|
17
|
+
assert Barcode.new(barcode).valid?
|
22
18
|
end
|
23
19
|
end
|
24
20
|
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
|
+
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-
|
11
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|