faker 2.1.1 → 2.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1d7c3b33cba95cfec8bda0796ff48fa6ecc6bf66e031ca1a5dfd9801f802e08
4
- data.tar.gz: dad43fb6acaebc8e6b8d95a03801621d0b484f7d8339107cf646bf7b3a5e3305
3
+ metadata.gz: 7462443ac85163e4a2bfaaa60b52b0153d209004c68f498be7796bafdca56bb8
4
+ data.tar.gz: 83792726058a2a4bcae5a9e65faebd7b89271323b04c509c5e85a3ed3dcf87d7
5
5
  SHA512:
6
- metadata.gz: c5a88255f6cb9d41be83134ddcdd3d54bf5517f66e165ad71a877b54caed0d612838596969095c28657936cfda88dcad5ef0d1ba21acfc45c9273af351c453e8
7
- data.tar.gz: e0b169592e5d671f62a98c8f16b53c3cc058342afd0f690fa72305a86366271f92ccfdf36ea1f394516ccc55999d06cbd55be5159bfe1aa69fc1ab57eaf41839
6
+ metadata.gz: 13e01c3cf5c0f2f4813b4ebd5f47da32f5445234cb0bbc217e7b1b4836c8578b9e32bdafbafe68c9d9c8f85e2a14ec84a9fa13c3b611c3fa7f566b6bdf1176eb
7
+ data.tar.gz: d4ff9c657474b461ed8b4f54ec16e982ba805d3bc5fd815757bcfbb67b3823fba776ba004af140a1afb6d5424990f6819eda943a7b4bdfe24841713b9eb29f4c
@@ -1,5 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## [v2.1.2](https://github.com/stympy/faker-ruby/faker/tree/2.1.2) (2019-10-08)
4
+
5
+ ## Enhancements
6
+
7
+ - [PR #1495](https://github.com/stympy/faker/pull/1495) Add Brazilian documents generation and documentation [@lucasqueiroz](https://github.com/lucasqueiroz)
8
+
9
+ ## Issues
10
+
11
+ We had to use `bundled with 1.7.3` to avoid some issues.
12
+
3
13
  ## [v2.1.1](https://github.com/stympy/faker/tree/2.1.1) (2019-10-08)
4
14
 
5
15
  ## Bug/Fixes
@@ -12,6 +12,9 @@ module Faker
12
12
  ].freeze
13
13
  ZA_RACE_DIGIT = '8'
14
14
  ZA_CITIZENSHIP_DIGITS = %w[0 1].freeze
15
+ BRAZILIAN_ID_FORMAT = /(\d{1,2})(\d{3})(\d{3})([\dX])/
16
+ BRAZILIAN_ID_FROM = 10_000_000
17
+ BRAZILIAN_ID_TO = 99_999_999
15
18
 
16
19
  class << self
17
20
  def valid
@@ -83,6 +86,17 @@ module Faker
83
86
  formatted ? format('%s.%s.%s-%s', *number.scan(/\d{2,3}/).flatten) : number
84
87
  end
85
88
 
89
+ alias brazilian_cpf brazilian_citizen_number
90
+
91
+ def brazilian_id(formatted: false)
92
+ digits = Faker::Number.between(to: BRAZILIAN_ID_FROM, from: BRAZILIAN_ID_TO).to_s
93
+ check_digit = brazilian_id_checksum_digit(digits)
94
+ number = [digits, check_digit].join
95
+ formatted ? format('%s.%s.%s-%s', *number.scan(BRAZILIAN_ID_FORMAT).flatten) : number
96
+ end
97
+
98
+ alias brazilian_rg brazilian_id
99
+
86
100
  private
87
101
 
88
102
  def south_african_id_checksum_digit(id_number)
@@ -104,13 +118,36 @@ module Faker
104
118
  end
105
119
 
106
120
  def brazilian_citizen_number_checksum_digit(digits)
107
- digit_sum = digits.chars.each_with_index.inject(0) do |acc, (digit, i)|
121
+ checksum = brazilian_document_checksum(digits)
122
+ brazilian_document_digit(checksum)
123
+ end
124
+
125
+ def brazilian_id_checksum_digit(digits)
126
+ checksum = brazilian_document_checksum(digits)
127
+ brazilian_document_digit(checksum, id: true)
128
+ end
129
+
130
+ def brazilian_document_checksum(digits)
131
+ digits.chars.each_with_index.inject(0) do |acc, (digit, i)|
108
132
  acc + digit.to_i * (digits.size + 1 - i)
109
133
  end * 10
110
- remainder = digit_sum % 11
134
+ end
135
+
136
+ def brazilian_document_digit(checksum, id = false)
137
+ remainder = checksum % 11
138
+ id ? brazilian_id_digit(remainder) : brazilian_citizen_number_digit(remainder)
139
+ end
140
+
141
+ def brazilian_citizen_number_digit(remainder)
111
142
  remainder == 10 ? '0' : remainder.to_s
112
143
  end
113
144
 
145
+ def brazilian_id_digit(remainder)
146
+ subtraction = 11 - remainder.to_i
147
+ digits = { 10 => 'X', 11 => '0' }
148
+ digits.include?(subtraction) ? digits[subtraction] : subtraction.to_s
149
+ end
150
+
114
151
  def _translate(key)
115
152
  parse("id_number.#{key}")
116
153
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faker #:nodoc:
4
- VERSION = '2.1.1'
4
+ VERSION = '2.1.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Curtis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-10 00:00:00.000000000 Z
12
+ date: 2019-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n