randamu 0.0.0 → 0.0.2

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.
@@ -0,0 +1,37 @@
1
+ module Randamu
2
+ class Map < Base
3
+ class << self
4
+ def full_address
5
+ "#{street}, #{rand(1..9999)}, #{city}, #{state} - #{zip_code}"
6
+ end
7
+
8
+ def street
9
+ load_data('map.streets').sample
10
+ end
11
+
12
+ def additional_address_data
13
+ load_data('map.additional_address_data').sample
14
+ end
15
+
16
+ def zip_code
17
+ load_data('map.zip_codes').sample
18
+ end
19
+
20
+ def state(region: nil, acronym: false)
21
+ state_acronym = region ? Dictionary::REGIONS[region].sample : Dictionary::STATES.keys.sample
22
+ return state_acronym if acronym
23
+
24
+ Dictionary::STATES[state_acronym]
25
+ end
26
+
27
+ def city(state: nil)
28
+ return load_data("map.states.#{state}").sample if state
29
+ load_data("map.states.#{Dictionary::STATES.keys.sample}").sample
30
+ end
31
+
32
+ def country
33
+ load_data('map.countries').sample
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ module Randamu
2
+ class Number < Base
3
+ class << self
4
+ def number(min: 0, max: 100)
5
+ rand(min..max)
6
+ # '.2f' % rand(min..max) -> to get a float number with 2 decimal places but return a string
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module Randamu
2
+ class Person < Base
3
+ extend NameGenerator
4
+ class << self
5
+ def profession
6
+ load_data('academic.professions').sample
7
+ end
8
+ def blood_type
9
+ %w(A+ A- B+ B- AB+ AB- O+ O-).sample
10
+ end
11
+ def gender
12
+ %w(male female other).sample
13
+ end
14
+
15
+ def marital_status
16
+ %w(Solteiro Casado Separado Divorciado Viúvo).sample
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ module Randamu
2
+ class Text < Base
3
+ class << self
4
+ def word(format: nil)
5
+ case format
6
+ when :upcase
7
+ load_data('texts.lorem').sample.upcase
8
+ when :downcase
9
+ load_data('texts.lorem').sample.downcase
10
+ when :capitalize
11
+ load_data('texts.lorem').sample.capitalize
12
+ else
13
+ load_data('texts.lorem').sample
14
+ end
15
+ end
16
+
17
+ def title(words: 3)
18
+ words.times.map { word }.join(' ').capitalize
19
+ end
20
+
21
+ def phrase(words: 4)
22
+ words.times.map { word }.join(' ').capitalize + '.'
23
+ end
24
+
25
+ def paragraph(phrases: 8)
26
+ phrases.times.map { phrase }.join(' ')
27
+ end
28
+
29
+ def text(paragraphs: 4)
30
+ paragraphs.times.map { paragraph }.join("\n\n")
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,95 @@
1
+ module DocumentGenerator
2
+ def cpf(valid: true)
3
+ return generate_valid_cpf if valid
4
+
5
+ generate_invalid_cpf
6
+ end
7
+
8
+ def rg
9
+ Array.new(9) { rand(0..9) }.join
10
+ end
11
+
12
+ def voter_registration
13
+ Array.new(12) { rand(0..9) }.join
14
+ end
15
+
16
+ def cnh
17
+ Array.new(9) { rand(0..9) }.join
18
+ end
19
+
20
+ #orgao emissor
21
+ def issuing_authority(full_name: false)
22
+ keys = load_data("doc.issuing_authority").keys
23
+ key = keys.sample
24
+
25
+ return "#{key} - #{load_data("doc.issuing_authority.#{key}")}" if full_name
26
+ key
27
+ end
28
+
29
+ def cnpj(valid: true)
30
+ return generate_valid_cnpj if valid
31
+
32
+ generate_invalid_cnpj
33
+ end
34
+
35
+ private
36
+ def generate_valid_cpf
37
+ cpf = Array.new(9) { rand(0..9) }
38
+ cpf << calculate_check_digit_cpf(cpf)
39
+ cpf << calculate_check_digit_cpf(cpf)
40
+ cpf.join
41
+ end
42
+
43
+ def generate_invalid_cpf
44
+ cpf = generate_valid_cpf
45
+ last_digit = cpf[-1]
46
+
47
+ while last_digit == cpf[-1]
48
+ new_digit = rand(0..9).to_s
49
+ cpf[-1] = new_digit
50
+ end
51
+
52
+ cpf
53
+ end
54
+
55
+ def calculate_check_digit_cpf(cpf)
56
+ sum = 0
57
+ cpf.each_with_index do |digit, index|
58
+ sum += digit * (cpf.size + 1 - index)
59
+ end
60
+
61
+ remainder = sum % 11
62
+ remainder < 2 ? 0 : 11 - remainder
63
+ end
64
+
65
+ def generate_valid_cnpj
66
+ cnpj = Array.new(12) { rand(0..9) }
67
+ cnpj << calculate_check_digit_cnpj(cnpj)
68
+ cnpj << calculate_check_digit_cnpj(cnpj)
69
+ cnpj.join
70
+ end
71
+
72
+ def generate_invalid_cnpj
73
+ cnpj = generate_valid_cnpj
74
+ last_digit = cnpj[-1]
75
+
76
+ while last_digit == cnpj[-1]
77
+ new_digit = rand(0..9).to_s
78
+ cnpj[-1] = new_digit
79
+ end
80
+
81
+ cnpj
82
+ end
83
+
84
+ def calculate_check_digit_cnpj(cnpj)
85
+ weights = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
86
+
87
+ sum = cnpj.each_with_index.reduce(0) do |acc, (digit, index)|
88
+ acc + digit * weights[index + (weights.size - cnpj.size)]
89
+ end
90
+
91
+ remainder = sum % 11
92
+ remainder < 2 ? 0 : 11 - remainder
93
+ end
94
+
95
+ end
@@ -0,0 +1,44 @@
1
+ module NameGenerator
2
+ GENDER = %w(male female).freeze
3
+
4
+ def first_name(gender: nil)
5
+ return load_db(gender).sample if !gender.nil? && GENDER.include?(gender.to_s)
6
+
7
+ gender = GENDER.sample
8
+ load_db(gender).sample
9
+ end
10
+
11
+ def last_name
12
+ load_db(:last).sample
13
+ end
14
+
15
+ def full_name(gender: nil)
16
+ "#{first_name(gender: gender)} #{last_name}"
17
+ end
18
+
19
+ def custom_name(length: 3, gender: nil)
20
+ generate_custom_name(first_name(gender: gender), length)
21
+ end
22
+
23
+ private
24
+ def load_db(type)
25
+ return load_data("names.#{type}_name") unless type.nil?
26
+
27
+ type = GENDER.sample
28
+ load_data("names.#{type}_name")
29
+ end
30
+
31
+ def generate_custom_name(initial_name, length)
32
+ return initial_name if length <= 1
33
+
34
+ (length - 1).times do
35
+ initial_name += " #{last_name}"
36
+ end
37
+
38
+ initial_name
39
+ end
40
+
41
+ def normalize(n)
42
+ n.gsub(/[^a-zA-Z]/, 'a')
43
+ end
44
+ end
@@ -0,0 +1,39 @@
1
+ module Dictionary
2
+ STATES = {
3
+ 'AC' => 'Acre',
4
+ 'AL' => 'Alagoas',
5
+ 'AP' => 'Amapá',
6
+ 'AM' => 'Amazonas',
7
+ 'BA' => 'Bahia',
8
+ 'CE' => 'Ceará',
9
+ 'DF' => 'Distrito Federal',
10
+ 'ES' => 'Espírito Santo',
11
+ 'GO' => 'Goiás',
12
+ 'MA' => 'Maranhão',
13
+ 'MT' => 'Mato Grosso',
14
+ 'MS' => 'Mato Grosso do Sul',
15
+ 'MG' => 'Minas Gerais',
16
+ 'PA' => 'Pará',
17
+ 'PB' => 'Paraíba',
18
+ 'PR' => 'Paraná',
19
+ 'PE' => 'Pernambuco',
20
+ 'PI' => 'Piauí',
21
+ 'RJ' => 'Rio de Janeiro',
22
+ 'RN' => 'Rio Grande do Norte',
23
+ 'RS' => 'Rio Grande do Sul',
24
+ 'RO' => 'Rondônia',
25
+ 'RR' => 'Roraima',
26
+ 'SC' => 'Santa Catarina',
27
+ 'SP' => 'São Paulo',
28
+ 'SE' => 'Sergipe',
29
+ 'TO' => 'Tocantins'
30
+ }.freeze
31
+
32
+ REGIONS = {
33
+ sudeste: %w[SP RJ MG ES],
34
+ sul: %w[RS SC PR],
35
+ centro_oeste: %w[GO MT MS DF],
36
+ norte: %w[AM RR AP PA TO RO AC],
37
+ nordeste: %w[MA PI CE RN PB PE AL SE BA]
38
+ }.freeze
39
+ end
data/lib/randamu.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'yaml'
2
+ require 'date'
2
3
 
3
4
  module Randamu
4
- DATA_DIR = File.join(__dir__, 'docs')
5
+ DATA_DIR = File.join(__dir__, 'data')
5
6
  DATA = Dir.glob(File.join(DATA_DIR, '**', '*.yml')).each_with_object({}) do |file, data|
6
7
  data.merge!(YAML.load_file(file))
7
8
  end
@@ -16,4 +17,6 @@ module Randamu
16
17
  end
17
18
  end
18
19
 
19
- Dir.glob(File.join(File.dirname(__FILE__), 'randamu', '/**/*.rb')).sort.each { |file| require file }
20
+ Dir.glob(File.join(File.dirname(__FILE__), 'randamu', '/support/*.rb')).each { |file| require file }
21
+ Dir.glob(File.join(File.dirname(__FILE__), 'randamu', '/generators/*.rb')).each { |file| require file }
22
+ Dir.glob(File.join(File.dirname(__FILE__), 'randamu', '/core/*.rb')).each { |file| require file }
metadata CHANGED
@@ -1,29 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: randamu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge Coutinho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-21 00:00:00.000000000 Z
11
+ date: 2024-10-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Random data generator
13
+ description: Random data generators
14
14
  email: jorgecoutinhodsn@gmail.com
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - lib/docs/address.yml
20
- - lib/docs/name.yml
21
- - lib/docs/text.yml
19
+ - lib/data/academic.yml
20
+ - lib/data/animals.yml
21
+ - lib/data/business.yml
22
+ - lib/data/doc.yml
23
+ - lib/data/emails.yml
24
+ - lib/data/map.yml
25
+ - lib/data/names.yml
26
+ - lib/data/phone.yml
27
+ - lib/data/texts.yml
22
28
  - lib/randamu.rb
23
- - lib/randamu/address.rb
24
- - lib/randamu/boolean.rb
25
- - lib/randamu/name.rb
26
- - lib/randamu/text.rb
29
+ - lib/randamu/core/academic.rb
30
+ - lib/randamu/core/account.rb
31
+ - lib/randamu/core/animal.rb
32
+ - lib/randamu/core/boolean.rb
33
+ - lib/randamu/core/business.rb
34
+ - lib/randamu/core/date.rb
35
+ - lib/randamu/core/doc.rb
36
+ - lib/randamu/core/map.rb
37
+ - lib/randamu/core/number.rb
38
+ - lib/randamu/core/person.rb
39
+ - lib/randamu/core/text.rb
40
+ - lib/randamu/generators/document_generator.rb
41
+ - lib/randamu/generators/name_generator.rb
42
+ - lib/randamu/support/dictionary.rb
27
43
  homepage: https://rubygems.org/gems/randamu
28
44
  licenses:
29
45
  - MIT
@@ -43,8 +59,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
59
  - !ruby/object:Gem::Version
44
60
  version: '0'
45
61
  requirements: []
46
- rubygems_version: 3.5.9
62
+ rubygems_version: 3.5.11
47
63
  signing_key:
48
64
  specification_version: 4
49
- summary: Random data generator
65
+ summary: Random data generators
50
66
  test_files: []