laranja 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress
@@ -1,77 +0,0 @@
1
- module Laranja
2
- class Address < Base
3
-
4
- def self.city
5
- strf [
6
- '%city_prefix :name%last_name',
7
- '%city_prefix :name%last_name %city_suffix',
8
- '%city_prefix %female_city_prefix :name%female_first_name',
9
- '%city_prefix %male_city_prefix :name%male_first_name',
10
- '%city_prefix %female_city_prefix :name%female_first_name %city_suffix',
11
- '%city_prefix %male_city_prefix :name%male_first_name %city_suffix',
12
- ':name%last_name %city_suffix',
13
- '%female_city_prefix :name%female_first_name',
14
- '%male_city_prefix :name%male_first_name',
15
- '%female_city_prefix :name%female_first_name %city_suffix',
16
- '%male_city_prefix :name%male_first_name %city_suffix'
17
- ].sample
18
- end
19
-
20
- def self.district
21
- strf [
22
- '%district_prefix :name%last_name',
23
- '%district_prefix :name%male_title :name%last_name',
24
- '%district_prefix :name%female_title :name%last_name'
25
- ].sample
26
- end
27
-
28
- def self.street
29
- strf [
30
- '%log_prefix :name%female_title :name%female_first_name :name%last_name',
31
- '%log_prefix :name%female_first_name :name%last_name',
32
- '%log_prefix :name%male_title :name%male_first_name :name%last_name :name%male_suffix',
33
- '%log_prefix :name%male_title :name%male_first_name :name%last_name',
34
- '%log_prefix :name%male_first_name :name%last_name :name%male_suffix',
35
- '%log_prefix :name%male_first_name :name%last_name'
36
- ].sample
37
- end
38
-
39
- def self.secondary
40
- strf('%secondary ') + (1 + rand(999)).to_s
41
- end
42
-
43
- def self.number
44
- (1 + rand(999)).to_s
45
- end
46
-
47
- def self.formatted_cep(ufab = nil)
48
- cep_builder(true, rand(6) != 0, ufab)
49
- end
50
-
51
- def self.cep(ufab = nil)
52
- cep_builder(false, rand(6) != 0, ufab)
53
- end
54
-
55
- def self.uf
56
- strf '%uf_name'
57
- end
58
-
59
- def self.uf_abbr
60
- strf '%uf_abbr'
61
- end
62
-
63
- private
64
-
65
- def self.cep_builder(formatted, suffix = true, ufab = nil)
66
- c = unufy(ufab, 'U####')
67
- c += '-' if formatted
68
- c += suffix ? '###' : '000'
69
- c.gsub(/#/) { rand(10).to_s }
70
- end
71
-
72
- def self.unufy(ufab, str)
73
- str.sub(/U/, ufab.nil? ? '#' : data('codigo_cep')[ufab.to_s.downcase].to_s)
74
- end
75
-
76
- end
77
- end
@@ -1,24 +0,0 @@
1
- module Laranja
2
- class CPF < Base
3
-
4
- def self.cpf(uf = nil)
5
- cpf = '########U'.sub(/U/, uf.nil? ? '#' : uf_code(uf)).gsub(/#/) { rand(10).to_s }
6
- v = [(0..8).inject(0) { |sum, i| sum + cpf[i].to_i * (10 - i) } % 11]
7
- v[0] = v[0] < 2 ? 0 : 11 - v[0]
8
- v[1] = ((0..8).inject(0) { |sum, i| sum + cpf[i].to_i * (11 - i) } + v[0] * 2) % 11
9
- v[1] = v[1] < 2 ? 0 : 11 - v[1]
10
- cpf += v.join
11
- end
12
-
13
- def self.formatted(uf = nil)
14
- c = cpf(uf)
15
- '%03d.%03d.%03d-%02d' % [ c[0..2].to_i, c[3..5].to_i, c[6..8].to_i, c[9..10].to_i ]
16
- end
17
-
18
- private
19
-
20
- def self.uf_code(uf)
21
- data('codigo_uf')[uf.to_s.downcase].to_s
22
- end
23
- end
24
- end
@@ -1,12 +0,0 @@
1
- module Laranja
2
- class Gender < Base
3
-
4
- def self.gender
5
- strf '%name'
6
- end
7
-
8
- def self.abbr
9
- strf '%abbr'
10
- end
11
- end
12
- end
@@ -1,26 +0,0 @@
1
- module Laranja
2
- class Internet < Base
3
-
4
- def self.email_for(name)
5
- strf username_for(name) + '@%email'
6
- end
7
-
8
- def self.email
9
- email_for(Laranja::Name.name)
10
- end
11
-
12
- def self.username_for(name, sep = ['', '.', '_'])
13
- name.gsub(/[^a-zA-Z0-9\s]/, '').split.join(sep.sample).downcase
14
- end
15
-
16
- def self.username
17
- username_for(Laranja::Name.name)
18
- end
19
-
20
- def self.password(min = 8, max = 128)
21
- characters = ('0'.upto('9').to_a + 'A'.upto('Z').to_a + 'a'.upto('z').to_a)
22
- size = min + rand(max - min)
23
- (1..size).inject('') { |passcode, i| passcode + characters.sample }
24
- end
25
- end
26
- end
@@ -1,33 +0,0 @@
1
- module Laranja
2
- class Name < Base
3
-
4
- def self.name(last_names = 1)
5
- strf format_builder(Laranja::Gender.abbr, last_names, rand(9) == 0)
6
- end
7
-
8
- def self.first_name
9
- strf format_builder(Laranja::Gender.abbr, 0)
10
- end
11
-
12
- def self.last_name
13
- strf format_builder(Laranja::Gender.abbr, 1, false, false)
14
- end
15
-
16
- private
17
-
18
- def self.format_builder(gender, last_names = 1, suffix = false, first_name = true)
19
- f = ''
20
- f += genderfy(gender, 'first_name ') if first_name
21
- f += '%last_name ' * last_names
22
- # TODO: Only men have suffix?
23
- f += genderfy(gender, 'suffix ') if suffix && gender.downcase == 'm'
24
- f
25
- end
26
-
27
- def self.genderfy(gender, attribute)
28
- g = gender.downcase == 'f' ? 'female' : 'male'
29
- "%#{g}_#{attribute}"
30
- end
31
-
32
- end
33
- end
@@ -1,26 +0,0 @@
1
- laranja:
2
- gender:
3
- name: ['Feminino', 'Masculino']
4
- abbr: ['F', 'M']
5
- address:
6
- log_prefix: ['Alameda', 'Avenida', 'Marginal', 'Rodovia', 'Rua', 'Travessa', 'Viela']
7
- city_prefix: ['Águas de', 'Campos de', 'Monte', 'Nova', 'Velha']
8
- female_city_prefix: ['Nossa Senhora', 'Santa']
9
- male_city_prefix: ['Santo', 'São']
10
- city_suffix: ['do Norte', 'do Sul']
11
- district_prefix: ['Bosque', 'Chácara', 'Jardim', 'Monte', 'Parque', 'Vila']
12
- secondary: ['Ap', 'Casa', 'Lote', 'Quadra']
13
- codigo_cep: { ac: 6, al: 5, ap: 6, am: 6, ba: 4, ce: 6, df: 7, es: 2, go: 7, ma: 6, mt: 7, ms: 7, mg: 3, pa: 6, pb: 5, pr: 8, pe: 5, pi: 6, rj: 2, rn: 5, rs: 9, ro: 7, rr: 6, sc: 8, sp: 1, se: 4, to: 7 }
14
- uf_abbr: ['AC', 'AL', 'AP', 'AM', 'BA', 'CE', 'DF', 'ES', 'GO', 'MA', 'MT', 'MS', 'MG', 'PA', 'PB', 'PR', 'PE', 'PI', 'RJ', 'RN', 'RS', 'RO', 'RR', 'SC', 'SP', 'SE', 'TO']
15
- uf_name: ['Acre', 'Alagoas', 'Amapá', 'Amazonas', 'Bahia', 'Ceará', 'Distrito Federal', 'Espírito Santo', 'Goiás', 'Maranhão', 'Mato Grosso', 'Mato Grosso do Sul', 'Minas Gerais', 'Pará', 'Paraíba', 'Paraná', 'Pernambuco', 'Piauí', 'Rio de Janeiro', 'Rio Grande do Norte', 'Rio Grande do Sul', 'Rondônia', 'Roraima', 'Santa Catarina', 'São Paulo', 'Sergipe', 'Tocantins']
16
- internet:
17
- email: ['bol.com.br', 'gmail.com', 'hotmail.com', 'live.com', 'terra.com.br', 'uol.com.br', 'yahoo.com']
18
- name:
19
- male_title: ['Barão', 'Conde', 'Dom', 'Dr', 'Duque', 'Engenheiro', 'General', 'Imperador', 'Presidente', 'Professor']
20
- female_title: ['Baronesa', 'Condessa', 'Dra', 'Duquesa', 'Engenheira', 'Imperatriz', 'Princesa', 'Professora']
21
- male_first_name: ['Alessandro', 'Alexandre', 'Antônio', 'Breno', 'Carlos', 'César', 'Danilo', 'Deneval', 'Eduardo', 'Esther', 'Elísio', 'Fábio', 'Fabrício', 'Félix', 'Feliciano', 'Frederico', 'Fabiano', 'Gustavo', 'Guilherme', 'Gúbio', 'Heitor', 'Hélio', 'Hugo', 'Ígor', 'João', 'Júlio', 'Kléber', 'Lucas', 'Marcos', 'Marcelo', 'Norberto', 'Paulo', 'Pablo', 'Pedro', 'Raul', 'Rafael', 'Ricardo', 'Roberto', 'Tertuliano', 'Vicente', 'Víctor', 'Yuri', 'Washington']
22
- female_first_name: ['Alessandra', 'Aline', 'Bruna', 'Carla', 'Célia', 'Cecília', 'Dalila', 'Eduarda', 'Fabrícia', 'Felícia', 'Isabel', 'Isabela', 'Joana', 'Júlia', 'Janaína', 'Karla', 'Lorena', 'Lorraine', 'Larissa', 'Meire', 'Marcela', 'Margarida', 'Mércia', 'Márcia', 'Marli', 'Morgana', 'Maria', 'Natália', 'Núbia', 'Ofélia', 'Paula', 'Rafaela', 'Roberta', 'Sílvia', 'Suélen', 'Sara', 'Talita', 'Vitória']
23
- last_name: ['Albuquerque', 'Barros', 'Batista', 'Braga', 'Carvalho', 'Costa', 'Cunha', 'Franco', 'Ladislau', 'Macedo', 'Martins', 'Melo', 'Moraes', 'Moreira', 'Nogueira', 'Oliveira', 'Pereira', 'Reis', 'Santos', 'Saraiva', 'Silva', 'Souza', 'Xavier']
24
- male_suffix: ['Junior', 'Neto', 'Filho']
25
- cpf:
26
- codigo_uf: { ac: 2, al: 4, ap: 2, am: 2, ba: 5, ce: 3, df: 1, es: 7, go: 1, ma: 3, mt: 1, ms: 1, mg: 6, pa: 2, pb: 4, pr: 9, pe: 4, pi: 3, rj: 7, rn: 4, rs: 0, ro: 2, rr: 2, sc: 9, sp: 8, se: 5, to: 1 }
@@ -1,89 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_examples 'non empty string generator' do |str|
4
- describe 'and' do
5
- it 'return a string' do
6
- expect(str).to be_a_kind_of(String)
7
- end
8
-
9
- it 'returns a non empty string' do
10
- expect(str).not_to be_empty
11
- end
12
- end
13
- end
14
-
15
- describe Laranja::Address do
16
- describe '#uf' do
17
- it_behaves_like 'non empty string generator', Laranja::Address.uf
18
- end
19
-
20
- describe '#uf_abbr' do
21
- it_behaves_like 'non empty string generator', Laranja::Address.uf_abbr
22
- it 'returns a 2 characters string' do
23
- expect(Laranja::Address.uf_abbr.size).to eq(2)
24
- end
25
- end
26
-
27
- describe '#formatted_cep' do
28
- it_behaves_like 'non empty string generator', Laranja::Address.formatted_cep
29
-
30
- it 'returns an 8 characters string' do
31
- expect(Laranja::Address.formatted_cep.size).to eq(9)
32
- end
33
-
34
- it 'returns a number only string' do
35
- expect(Laranja::Address.formatted_cep).to match(/\d{5}-\d{3}/)
36
- end
37
-
38
- it 'has the UF digit if an UF is specified' do
39
- expect(Laranja::Address.formatted_cep(:ce)[0].to_i).to eq(6)
40
- expect(Laranja::Address.formatted_cep(:BA)[0].to_i).to eq(4)
41
- expect(Laranja::Address.formatted_cep('rj')[0].to_i).to eq(2)
42
- expect(Laranja::Address.formatted_cep('RS')[0].to_i).to eq(9)
43
- expect(Laranja::Address.formatted_cep(:sp)[0].to_i).to eq(1)
44
- end
45
- end
46
-
47
- describe '#cep' do
48
- it_behaves_like 'non empty string generator', Laranja::Address.cep
49
-
50
- it 'returns an 8 characters string' do
51
- expect(Laranja::Address.cep.size).to eq(8)
52
- end
53
-
54
- it 'returns a number only string' do
55
- expect(Laranja::Address.cep).to match(/\d{8}/)
56
- end
57
-
58
- it 'has the UF digit if an UF is specified' do
59
- expect(Laranja::Address.cep(:ce)[0].to_i).to eq(6)
60
- expect(Laranja::Address.cep(:BA)[0].to_i).to eq(4)
61
- expect(Laranja::Address.cep('rj')[0].to_i).to eq(2)
62
- expect(Laranja::Address.cep('RS')[0].to_i).to eq(9)
63
- expect(Laranja::Address.cep(:sp)[0].to_i).to eq(1)
64
- end
65
- end
66
-
67
- describe '#city' do
68
- it_behaves_like 'non empty string generator', Laranja::Address.city
69
- end
70
-
71
- describe '#street' do
72
- it_behaves_like 'non empty string generator', Laranja::Address.street
73
- end
74
-
75
- describe '#district' do
76
- it_behaves_like 'non empty string generator', Laranja::Address.district
77
- end
78
-
79
- describe '#secondary' do
80
- it_behaves_like 'non empty string generator', Laranja::Address.secondary
81
- end
82
-
83
- describe '#number' do
84
- it_behaves_like 'non empty string generator', Laranja::Address.number
85
- it 'returns a number only string' do
86
- expect(Laranja::Address.number).to match(/\d+/)
87
- end
88
- end
89
- end
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_examples 'a cpf generator' do |cpf|
4
- describe 'and' do
5
- it 'return a string' do
6
- expect(cpf).to be_a_kind_of(String)
7
- end
8
-
9
- it 'return a string with 11 characters' do
10
- expect(cpf.size).to eq(11)
11
- end
12
-
13
- it 'return a valid cpf' do
14
- v1, v2 = 0, 0
15
- for i in 0..8
16
- v1 += cpf[i].to_i * (10 - i)
17
- v2 += cpf[i].to_i * (11 - i)
18
- end
19
- v1 = v1 % 11
20
- if v1 < 2
21
- v1 = 0
22
- else
23
- v1 = 11 - v1
24
- end
25
- v2 += v1 * 2
26
- v2 = v2 % 11
27
- if v2 < 2
28
- v2 = 0
29
- else
30
- v2 = 11 - v2
31
- end
32
- expect(cpf[-2].to_i).to eq(v1)
33
- expect(cpf[-1].to_i).to eq(v2)
34
- end
35
- end
36
- end
37
-
38
- describe Laranja::CPF do
39
- describe '#cpf' do
40
- it_behaves_like 'a cpf generator', Laranja::CPF.cpf
41
- it_behaves_like 'a cpf generator', Laranja::CPF.cpf(:ce)
42
- it_behaves_like 'a cpf generator', Laranja::CPF.cpf(:BA)
43
- it_behaves_like 'a cpf generator', Laranja::CPF.cpf('rj')
44
- it_behaves_like 'a cpf generator', Laranja::CPF.cpf('RS')
45
- it_behaves_like 'a cpf generator', Laranja::CPF.cpf(:sp)
46
-
47
- it 'has the UF digit if an UF is specified' do
48
- expect(Laranja::CPF.cpf(:ce)[-3].to_i).to eq(3)
49
- expect(Laranja::CPF.cpf(:BA)[-3].to_i).to eq(5)
50
- expect(Laranja::CPF.cpf('rj')[-3].to_i).to eq(7)
51
- expect(Laranja::CPF.cpf('RS')[-3].to_i).to eq(0)
52
- expect(Laranja::CPF.cpf(:sp)[-3].to_i).to eq(8)
53
- end
54
- end
55
-
56
- describe '#formatted' do
57
- it_behaves_like 'a cpf generator', Laranja::CPF.formatted.gsub(/\D+/, '')
58
- it 'return a formatted cpf string' do
59
- expect(Laranja::CPF.formatted).to match(/\d{3}\.\d{3}\.\d{3}-\d{2}/)
60
- end
61
- end
62
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Laranja::Gender do
4
- describe '#gender' do
5
- it 'returns a string' do
6
- expect(Laranja::Gender.gender).to be_a_kind_of(String)
7
- end
8
-
9
- it 'returns a non empty string' do
10
- expect(Laranja::Gender.gender).not_to be_empty
11
- end
12
- end
13
-
14
- describe '#abbr' do
15
- it 'returns a string' do
16
- expect(Laranja::Gender.abbr).to be_a_kind_of(String)
17
- end
18
-
19
- it 'returns an 1 character string' do
20
- expect(Laranja::Gender.abbr.size).to eq(1)
21
- end
22
- end
23
- end
@@ -1,77 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Laranja::Internet do
4
- describe '#email' do
5
- it 'returns a string' do
6
- expect(Laranja::Internet.email).to be_a_kind_of(String)
7
- end
8
-
9
- it 'returns a valid email' do
10
- expect(Laranja::Internet.email).to match(/^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i)
11
- end
12
- end
13
-
14
- describe '#strfemail' do
15
-
16
- let (:name) { 'John Doe' }
17
-
18
- it 'returns a string' do
19
- expect(Laranja::Internet.email_for(name)).to be_a_kind_of(String)
20
- end
21
-
22
- it 'returns a valid email' do
23
- expect(Laranja::Internet.email_for(name)).to match(/^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i)
24
- end
25
-
26
- it 'returns an email for the given name' do
27
- expect(Laranja::Internet.email_for(name)).to include('john')
28
- expect(Laranja::Internet.email_for(name)).to include('doe')
29
- end
30
- end
31
-
32
- describe '#username' do
33
- it 'returns a string' do
34
- expect(Laranja::Internet.username).to be_a_kind_of(String)
35
- end
36
-
37
- it 'returns a non empty string' do
38
- expect(Laranja::Internet.username).not_to be_empty
39
- end
40
- end
41
-
42
- describe '#strfusername' do
43
-
44
- let (:name) { 'John Doe' }
45
-
46
- it 'returns a string' do
47
- expect(Laranja::Internet.username_for(name)).to be_a_kind_of(String)
48
- end
49
-
50
- it 'returns an username for the given name' do
51
- expect(Laranja::Internet.username_for(name)).to include('john')
52
- expect(Laranja::Internet.username_for(name)).to include('doe')
53
- end
54
-
55
- it 'returns an username for the given name and separator' do
56
- expect(Laranja::Internet.username_for(name, ['-'])).to eq('john-doe')
57
- end
58
- end
59
-
60
- describe '#password' do
61
- it 'returns a string' do
62
- expect(Laranja::Internet.password).to be_a_kind_of(String)
63
- end
64
-
65
- it 'returns an alphanumeric string' do
66
- expect(Laranja::Internet.password).not_to match(/\W/)
67
- end
68
-
69
- it 'returns a password with minimum length' do
70
- expect(Laranja::Internet.password(32).size).to be >= 32
71
- end
72
-
73
- it 'returns a password with minimum and maximum length' do
74
- expect(Laranja::Internet.password(64, 64).size).to eq(64)
75
- end
76
- end
77
- end