codigo_postal 0.0.1 → 0.0.3
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/lib/codigo_postal.rb +3 -3
- data/test/test_codigo_postal.rb +19 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d29b9410fcafd6fdd062a01bc0c75dba793485e4ea6207b785ed0d66ca8fba64
|
4
|
+
data.tar.gz: 847ec9e1977583f0313c0c07a5435b07c62e99afe42afb19730671417e89d9a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 358099ecb11d4d87b04e59c80abeedfc244827f387506c1d44234cc959bf0a17ffc56bd6d263b369a344835e99f82232ac37406ddfcdc198a57cdf93579abead
|
7
|
+
data.tar.gz: 5d541f5d847cf286fdebbc5feb90fb4ec2197134a5a47f52365e5b0da06abc399cacd9ecc79b5d3fec256ac95f147e36ab2dc7662fc4177c26487b7b8353fc0e
|
data/lib/codigo_postal.rb
CHANGED
@@ -34,7 +34,7 @@ class CodigoPostal
|
|
34
34
|
|
35
35
|
attr_reader :state_code, :state_name, :cep_formatted, :cep_digits
|
36
36
|
def initialize(cep)
|
37
|
-
cep_fields = match_cep cep.to_s
|
37
|
+
cep_fields = match_cep cep.to_s.strip
|
38
38
|
if !cep_fields.nil?
|
39
39
|
@cep_digits = "#{cep_fields[0]}#{cep_fields[1]}#{cep_fields[2]}".to_i
|
40
40
|
@cep_formatted = "#{cep_fields[0].rjust(2, '0')}#{cep_fields[1]}-#{cep_fields[2]}"
|
@@ -45,9 +45,9 @@ class CodigoPostal
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def find_state_by_cep
|
48
|
-
|
48
|
+
@cep_digits
|
49
49
|
CEP_RANGES.sort_by { |range| range[:range_end] }.each do |cep_range|
|
50
|
-
return cep_range if
|
50
|
+
return cep_range if @cep_digits <= cep_range[:range_end]
|
51
51
|
end
|
52
52
|
nil
|
53
53
|
end
|
data/test/test_codigo_postal.rb
CHANGED
@@ -108,5 +108,24 @@ end
|
|
108
108
|
|
109
109
|
end
|
110
110
|
|
111
|
+
def test_readme_examples
|
112
|
+
assert_output("SP\nSão Paulo\n01001-000\n") do
|
113
|
+
cep = CodigoPostal.new(1001000)
|
114
|
+
puts cep.state_code # => 'SP'
|
115
|
+
puts cep.state_name # => 'São Paulo'
|
116
|
+
puts cep.to_s # => '01001-000'
|
117
|
+
end
|
118
|
+
|
119
|
+
assert_output("true\n") do
|
120
|
+
cep1 = CodigoPostal.new(4094050)
|
121
|
+
cep2 = CodigoPostal.new("04.094-050")
|
122
|
+
puts cep1 == cep2 # => true
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_strip_whitspace
|
127
|
+
assert_equal CodigoPostal.new(' 04.094-050 '), CodigoPostal.new('04.094-050')
|
128
|
+
end
|
129
|
+
|
111
130
|
end
|
112
131
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codigo_postal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felipe Mesquita
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -24,7 +24,8 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
|
-
description:
|
27
|
+
description: Validate, format and get the corresponding Brazilian state for a CEP
|
28
|
+
without making HTTP requests.
|
28
29
|
email: felipemesquita@hey.com
|
29
30
|
executables: []
|
30
31
|
extensions: []
|
@@ -51,9 +52,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
52
|
- !ruby/object:Gem::Version
|
52
53
|
version: '0'
|
53
54
|
requirements: []
|
54
|
-
rubygems_version: 3.4.
|
55
|
+
rubygems_version: 3.4.13
|
55
56
|
signing_key:
|
56
57
|
specification_version: 4
|
57
|
-
summary:
|
58
|
+
summary: An offline gem to find Brazilian states by postal code
|
58
59
|
test_files:
|
59
60
|
- test/test_codigo_postal.rb
|