correios-sro_validator 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/correios/sro_validator.rb +17 -5
- data/lib/correios/version.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: 0b5da789d31c588b8c9bf06f532d797db7fabddb
|
|
4
|
+
data.tar.gz: 286ae560e7c45bf75d6664398d36a058f33c5efe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35cd19306428b0cb5f708ee664b1771069ed7dd98bd54d693f4d7d8856287ceed3ba11c4eba7ee20673783dbd4955f97b54eda22faa35743be3c55e5750f4563
|
|
7
|
+
data.tar.gz: a9706497418a02de17f3c3dcf6ef1f4fe4d2b4bf63668c318dd988157384ca4e75a0caa04676d36be8fe0e24585f7ba8712d4d7c0c073032573d09dcbd86548c
|
data/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Correios::SROValidator
|
|
2
2
|
|
|
3
|
+
[](https://travis-ci.org/lemanchester/correios-sro_validator)
|
|
4
|
+
|
|
3
5
|
Validates the SRO (Sistema de Rastreamento de Objetos dos Correios) structure to guarantee it's a Correios SRO.
|
|
4
6
|
|
|
5
7
|

|
|
@@ -21,13 +21,23 @@ module Correios
|
|
|
21
21
|
|
|
22
22
|
attr_reader :sro, :numbers, :verification_digit
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
# Initializer the SROValidator
|
|
26
|
+
#
|
|
27
|
+
# @param [String] sro describe sro
|
|
28
|
+
# @param [String] suffix_match = 'BR' the regex match suffix (BR as default)
|
|
29
|
+
# @return [self] SROValidator
|
|
30
|
+
def initialize(sro, suffix_match = 'BR')
|
|
25
31
|
@sro = sro
|
|
26
|
-
@sro =~ /^[A-Z|a-z]{2}([0-9]{8})([0-9])
|
|
27
|
-
@numbers = $1
|
|
32
|
+
@sro =~ /^[A-Z|a-z]{2}([0-9]{8})([0-9])#{suffix_match}$/
|
|
33
|
+
@numbers = ($1 || "")
|
|
28
34
|
@verification_digit = $2.to_i
|
|
29
35
|
end
|
|
30
36
|
|
|
37
|
+
# Return if the SRO is valid or not
|
|
38
|
+
#
|
|
39
|
+
# @return [True] true when the 9th digit matchs the validation algorithm
|
|
40
|
+
# @return [False] false otherwise
|
|
31
41
|
def valid?
|
|
32
42
|
result == verification_digit
|
|
33
43
|
end
|
|
@@ -39,11 +49,13 @@ module Correios
|
|
|
39
49
|
end
|
|
40
50
|
|
|
41
51
|
def mod
|
|
42
|
-
weighted_mean % 11
|
|
52
|
+
@mod ||= weighted_mean % 11
|
|
43
53
|
end
|
|
44
54
|
|
|
45
55
|
def weighted_mean
|
|
46
|
-
sro_array.zip(WEIGHTING_FACTORS)
|
|
56
|
+
sro_array.zip(WEIGHTING_FACTORS)
|
|
57
|
+
.map { |a| a.inject(:*) }
|
|
58
|
+
.inject(:+) || Float::INFINITY
|
|
47
59
|
end
|
|
48
60
|
|
|
49
61
|
def sro_array
|
data/lib/correios/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: correios-sro_validator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lennon Manchester
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-06-
|
|
11
|
+
date: 2016-06-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|