conecta_address_br 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cities.txt +5570 -0
- data/lib/conecta_address_br.rb +54 -34
- data/lib/conecta_address_br/version.rb +2 -2
- metadata +3 -24
- data/lib/conecta_address_br/states/states.rb +0 -11
- data/lib/locales/addressList.yml +0 -63
data/lib/conecta_address_br.rb
CHANGED
@@ -1,47 +1,67 @@
|
|
1
1
|
require "conecta_address_br"
|
2
2
|
|
3
|
-
require 'i18n'
|
4
|
-
require 'set' # Fixes a bug in i18n 0.6.11
|
5
|
-
|
6
|
-
I18n.load_path += Dir[File.join(mydir, 'locales', '**/*.yml')]
|
7
|
-
I18n.reload! if I18n.backend.initialized?
|
8
|
-
|
9
3
|
module ConectaAddressBr
|
10
|
-
class
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
class ConectaAddressBr::States
|
5
|
+
def self.all()
|
6
|
+
return [
|
7
|
+
"Acre",
|
8
|
+
"Alagoas",
|
9
|
+
"Amapá",
|
10
|
+
"Amazonas",
|
11
|
+
"Bahia",
|
12
|
+
"Ceará",
|
13
|
+
"Distrito Federal",
|
14
|
+
"Espírito Santo",
|
15
|
+
"Goiás",
|
16
|
+
"Maranhão",
|
17
|
+
"Mato Grosso",
|
18
|
+
"Mato Grosso do Sul",
|
19
|
+
"Minas Gerais",
|
20
|
+
"Paraíba",
|
21
|
+
"Paraná",
|
22
|
+
"Pará",
|
23
|
+
"Pernambuco",
|
24
|
+
"Piauí",
|
25
|
+
"Rio de Janeiro",
|
26
|
+
"Rio Grande do Norte",
|
27
|
+
"Rio Grande do Sul",
|
28
|
+
"Rondônia",
|
29
|
+
"Roraima",
|
30
|
+
"Santa Catarina",
|
31
|
+
"São Paulo",
|
32
|
+
"Sergipe",
|
33
|
+
"Tocantins"
|
34
|
+
]
|
35
|
+
end
|
36
|
+
end
|
15
37
|
|
16
|
-
|
17
|
-
|
38
|
+
class ConectaAddressBr::Cities
|
39
|
+
def self.by_state(state_initial)
|
40
|
+
list = []
|
41
|
+
File.open("lib/cities.txt").each do |line|
|
42
|
+
tmp = line.split()
|
43
|
+
state = tmp.first
|
44
|
+
if state == state_initial
|
45
|
+
tmp.delete(state_initial)
|
46
|
+
list.push(tmp.join(" "))
|
47
|
+
end
|
18
48
|
end
|
49
|
+
return list
|
50
|
+
end
|
19
51
|
|
20
|
-
|
21
|
-
|
52
|
+
def self.all()
|
53
|
+
list = []
|
54
|
+
File.open("lib/cities.txt").each do |line|
|
55
|
+
tmp = line.split()
|
56
|
+
tmp.delete(tmp.first)
|
57
|
+
list.push(tmp.join(" "))
|
22
58
|
end
|
59
|
+
return list
|
23
60
|
end
|
24
61
|
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class Base
|
28
|
-
def regexify(reg)
|
29
|
-
reg = reg.source if reg.respond_to?(:source) # Handle either a Regexp or a String that looks like a Regexp
|
30
|
-
reg
|
31
|
-
.gsub(%r{^\/?\^?}, '').gsub(%r{\$?\/?$}, '') # Ditch the anchors
|
32
|
-
.gsub(/\{(\d+)\}/, '{\1,\1}').gsub(/\?/, '{0,1}') # All {2} become {2,2} and ? become {0,1}
|
33
|
-
.gsub(/(\[[^\]]+\])\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # [12]{1,2} becomes [12] or [12][12]
|
34
|
-
.gsub(/(\([^\)]+\))\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # (12|34){1,2} becomes (12|34) or (12|34)(12|34)
|
35
|
-
.gsub(/(\\?.)\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d
|
36
|
-
.gsub(/\((.*?)\)/) { |match| sample(match.gsub(/[\(\)]/, '').split('|')) } # (this|that) becomes 'this' or 'that'
|
37
|
-
.gsub(/\[([^\]]+)\]/) { |match| match.gsub(/(\w\-\w)/) { |range| sample(Array(Range.new(*range.split('-')))) } } # All A-Z inside of [] become C (or X, or whatever)
|
38
|
-
.gsub(/\[([^\]]+)\]/) { |_match| sample(Regexp.last_match(1).split('')) } # All [ABC] become B (or A or C)
|
39
|
-
.gsub('\d') { |_match| sample(Numbers) }
|
40
|
-
.gsub('\w') { |_match| sample(Letters) }
|
41
|
-
end
|
42
62
|
|
43
63
|
def fetch(keys)
|
44
|
-
fetched = translate("
|
64
|
+
fetched = translate("addressList.#{key}")
|
45
65
|
fetched = fetched.last if fetched.size <= 1
|
46
66
|
if !fetched.respond_to?(:sample) && fetched.match(%r{^\/}) && fetched.match(%r{\/$}) # A regex
|
47
67
|
regexify(fetched)
|
@@ -49,4 +69,4 @@ class Base
|
|
49
69
|
fetched
|
50
70
|
end
|
51
71
|
end
|
52
|
-
end
|
72
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module ConectaAddressBr
|
2
|
-
|
3
|
-
end
|
2
|
+
VERSION = "0.1.3"
|
3
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conecta_address_br
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Lessa, Eduardo Martins
|
@@ -9,28 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-11-
|
12
|
+
date: 2019-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: i18n
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ">="
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '1.6'
|
21
|
-
- - "<"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: '1.8'
|
24
|
-
type: :runtime
|
25
|
-
prerelease: false
|
26
|
-
version_requirements: !ruby/object:Gem::Requirement
|
27
|
-
requirements:
|
28
|
-
- - ">="
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '1.6'
|
31
|
-
- - "<"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.8'
|
34
14
|
- !ruby/object:Gem::Dependency
|
35
15
|
name: bundler
|
36
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,10 +47,9 @@ extensions: []
|
|
67
47
|
extra_rdoc_files: []
|
68
48
|
files:
|
69
49
|
- README.md
|
50
|
+
- lib/cities.txt
|
70
51
|
- lib/conecta_address_br.rb
|
71
|
-
- lib/conecta_address_br/states/states.rb
|
72
52
|
- lib/conecta_address_br/version.rb
|
73
|
-
- lib/locales/addressList.yml
|
74
53
|
homepage: https://github.com/conectaai/address-br
|
75
54
|
licenses:
|
76
55
|
- MIT
|
data/lib/locales/addressList.yml
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
brasil:
|
2
|
-
estados:
|
3
|
-
[
|
4
|
-
"Acre",
|
5
|
-
"Alagoas",
|
6
|
-
"Amapá",
|
7
|
-
"Amazonas",
|
8
|
-
"Bahia",
|
9
|
-
"Ceará",
|
10
|
-
"Distrito Federal",
|
11
|
-
"Espírito Santo",
|
12
|
-
"Goiás",
|
13
|
-
"Maranhão",
|
14
|
-
"Mato Grosso",
|
15
|
-
"Mato Grosso do Sul",
|
16
|
-
"Minas Gerais",
|
17
|
-
"Paraíba",
|
18
|
-
"Paraná",
|
19
|
-
"Pará",
|
20
|
-
"Pernambuco",
|
21
|
-
"Piauí",
|
22
|
-
"Rio de Janeiro",
|
23
|
-
"Rio Grande do Norte",
|
24
|
-
"Rio Grande do Sul",
|
25
|
-
"Rondônia",
|
26
|
-
"Roraima",
|
27
|
-
"Santa Catarina",
|
28
|
-
"São Paulo",
|
29
|
-
"Sergipe",
|
30
|
-
"Tocantins"
|
31
|
-
]
|
32
|
-
AC:
|
33
|
-
AL:
|
34
|
-
AP:
|
35
|
-
AM:
|
36
|
-
BA:
|
37
|
-
CE:
|
38
|
-
DF:
|
39
|
-
ES:
|
40
|
-
GO:
|
41
|
-
MA:
|
42
|
-
MT:
|
43
|
-
MS:
|
44
|
-
MG:
|
45
|
-
PB:
|
46
|
-
PR:
|
47
|
-
PE:
|
48
|
-
PI:
|
49
|
-
RJ:
|
50
|
-
[
|
51
|
-
"Niterói",
|
52
|
-
"Rio de Janeiro",
|
53
|
-
"São Gonçalo",
|
54
|
-
"Macaé"
|
55
|
-
]
|
56
|
-
RN:
|
57
|
-
RS:
|
58
|
-
RO:
|
59
|
-
RR:
|
60
|
-
SC:
|
61
|
-
SP:
|
62
|
-
SE:
|
63
|
-
TO:
|