digit_checksum 0.1.1 → 0.2.0
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/README.md +105 -19
- data/examples/brazilian_cnpj.rb +7 -7
- data/examples/brazilian_cpf.rb +7 -7
- data/examples/h4ck.rb +8 -8
- data/lib/digit_checksum/base_document.rb +83 -32
- data/lib/digit_checksum/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7758954adbce872ca492737d6848987a4e0c3e4
|
4
|
+
data.tar.gz: 656edafd10e3c9c70658cfa7ee2fae30072a3c7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd65ebf917f946649b808035ef6db3949114c998bca7b81e0a53f9e917bd50aec6e90aa5217179143677c721faab6f0f9094445bad8840a7a7e415c719a9ea01
|
7
|
+
data.tar.gz: 3125454badcd0a2773719736d3b638c4fa1e9061c270936f9af8a2baef1a8a9b90e2eb70bcdbaecf292ba992c26a64ce86f5e49691546da623eb3da2534ece1e
|
data/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# DigitCheckSum
|
2
2
|
|
3
|
+
[](https://travis-ci.org/fidelisrafael/digit_checksum)
|
4
|
+
|
3
5
|
Hi there, I'm glad you're looking in this gem!
|
4
6
|
The aim of this gem is to allow **any kind** of document to be validated e generated through calculation of [**Check Digit/Digit Checksum**](https://en.wikipedia.org/wiki/Check_digit).
|
5
7
|
|
6
8
|
What this mean? This mean that you can **validate** and **generate fake numbers** of any kind of documents such: **Passport numbers**, **Federal ID number**, **Books ISBN**, or even **create your own document** number, check `examples/` for more details.
|
9
|
+
One of the greatest abilitys of this library is allowing to check digit checksum of digits in **ANY POSITION** of the document, not only for the last digits.
|
7
10
|
|
8
11
|
**Tip**: Check [`examples/h4ck.rb`](examples/h4ck.rb) to see `h4ck` document specification, this is a sample document who can be manipulated using this library!
|
9
12
|
|
@@ -14,7 +17,7 @@ What this mean? This mean that you can **validate** and **generate fake numbers*
|
|
14
17
|
Add this line to your application's Gemfile:
|
15
18
|
|
16
19
|
```ruby
|
17
|
-
gem 'digit_checksum'
|
20
|
+
gem 'digit_checksum', '~> 0.2.0'
|
18
21
|
```
|
19
22
|
|
20
23
|
And then execute:
|
@@ -38,25 +41,24 @@ Don't you believe me? See for yourself an example:
|
|
38
41
|
require 'digit_checksum'
|
39
42
|
|
40
43
|
class CNPJ < DigitChecksum::BaseDocument
|
41
|
-
# masks that will be used to calculate each check digit
|
42
|
-
|
43
|
-
|
44
|
+
# weights masks that will be used to calculate each check digit
|
45
|
+
set_verify_digits_weights first: %w(5 4 3 2 9 8 7 6 5 4 3 2),
|
46
|
+
second: %w(6 5 4 3 2 9 8 7 6 5 4 3 2)
|
44
47
|
|
45
48
|
# remove any non digit from document number
|
46
|
-
|
47
|
-
clear_number_regexp %r{[^(\d+)]}
|
49
|
+
set_clear_number_regexp %r{[^(\d+)]}
|
48
50
|
|
49
51
|
# use modulo 11 as algorithm (can be any value)
|
50
|
-
|
52
|
+
set_division_factor_modulo 11
|
51
53
|
|
52
54
|
# match format such as: 99.999.999/9999-99 | 99-999-999/9999-99 | 99999999/999999 | 99999999999999
|
53
|
-
|
55
|
+
set_valid_format_regexp %r{(\d{2})[-.]?(\d{3})[-.]?(\d{3})[\/]?(\d{4})[-.]?(\d{2})}
|
54
56
|
|
55
57
|
# mask utilized to prettify doc number
|
56
|
-
|
58
|
+
set_pretty_format_mask %(%s.%s.%s/%s-%s)
|
57
59
|
|
58
60
|
# numbers sampled to generate new document numbers
|
59
|
-
|
61
|
+
set_generator_numbers (0..9).to_a
|
60
62
|
end
|
61
63
|
```
|
62
64
|
|
@@ -67,8 +69,20 @@ The example below it's intent to validated brazilian `CNPJ` documents, equivalen
|
|
67
69
|
```ruby
|
68
70
|
CNPJ.generate # "79.552.921/0786-55"
|
69
71
|
|
70
|
-
|
72
|
+
# without pretty formating
|
73
|
+
CNPJ.generate(false) # 85215313606778
|
74
|
+
|
75
|
+
# You can calculate only random root numbers
|
76
|
+
root_numbers = CNPJ.generate_root_numbers
|
77
|
+
# => [3, 8, 9, 3, 2, 5, 9, 5, 0, 2, 6, 6]
|
71
78
|
|
79
|
+
CNPJ.calculate_verify_digits(root_numbers) # [6,7]
|
80
|
+
|
81
|
+
# To insert the verify digits in the CORRECT positions
|
82
|
+
# Remember: The correct position MAY NOT be the last positions
|
83
|
+
# So use `append_verify_digits` to handle this
|
84
|
+
CNPJ.pretty(CNPJ.append_verify_digits(root_numbers))
|
85
|
+
=> "38.932.595/0266-67"
|
72
86
|
```
|
73
87
|
|
74
88
|
|
@@ -79,6 +93,21 @@ CNPJ.calculate_verify_digits("123.456.78/0001") # [9,5]
|
|
79
93
|
|
80
94
|
# invalid format
|
81
95
|
CNPJ.calculate_verify_digits("123.456.78/00001") # []
|
96
|
+
|
97
|
+
CNPJ.pretty(CNPJ.append_verify_digits("123.456.78/0001")) # "123.456.78/0001-95"
|
98
|
+
|
99
|
+
document = "123.456.78/0001-95"
|
100
|
+
CNPJ.remove_verify_digits!(document)
|
101
|
+
# [9,5]
|
102
|
+
document
|
103
|
+
# => 123456780001
|
104
|
+
CNPJ.pretty(CNPJ.append_verify_digits(document))
|
105
|
+
# => "12.345.678/0001-95"
|
106
|
+
|
107
|
+
# The last two characters position
|
108
|
+
CNPJ.obtain_verify_digits_positions
|
109
|
+
# => [12, 13]
|
110
|
+
|
82
111
|
```
|
83
112
|
|
84
113
|
#### Validate documents numbers
|
@@ -98,33 +127,90 @@ CNPJ.valid?(12345678000195) # true
|
|
98
127
|
#### Normalize and format documents number
|
99
128
|
|
100
129
|
```ruby
|
101
|
-
# belows returns [1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 1, 9, 5]
|
102
|
-
CNPJ.normalize_number("123.456.78/0001-95")
|
103
130
|
|
104
|
-
|
131
|
+
# Get a array representation of document number
|
132
|
+
CNPJ.normalize_number("123.456.78/0001-95")
|
133
|
+
# => [1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 1, 9, 5]
|
105
134
|
|
106
|
-
|
135
|
+
# also aliased as CNPJ.pretty_formatted(number) or CNPJ.formatted(number)
|
136
|
+
CNPJ.pretty("12345678000195") # "123.456.78/0001-95"
|
107
137
|
|
108
|
-
|
138
|
+
# also aliased as CNPJ.clear_number(number)
|
139
|
+
CNPJ.stripped("123.456.78/0001-95")
|
140
|
+
# => "12345678000195"
|
109
141
|
```
|
110
142
|
|
111
143
|
See `examples/`for more detailed samples.
|
112
144
|
|
113
145
|
|
146
|
+
---
|
147
|
+
|
148
|
+
### Custom verify digits positions
|
149
|
+
|
150
|
+
In **most**(*but not necessarily all*) documents formats the check digits positions are the last characters, but this library also allow you
|
151
|
+
to calculate check digits in any position in the middle of the document number, see an example:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
class MyDocument < DigitChecksum::BaseDocument
|
155
|
+
set_division_factor_modulo 11
|
156
|
+
|
157
|
+
set_clear_number_regexp %r{[^(\d+)]}
|
158
|
+
|
159
|
+
set_root_documents_digits_count 10
|
160
|
+
|
161
|
+
set_verify_digits_positions [8, 11]
|
162
|
+
|
163
|
+
set_verify_digits_weights first: %w(1 3 4 5 6 7 8 10),
|
164
|
+
last: %w(3 2 10 9 8 7 6 5 4 3 2)
|
165
|
+
|
166
|
+
set_valid_format_regexp %r{(\d{3})[-.]?(\d{3})[-.]?(\d{3})[-.]?(\d{3})}
|
167
|
+
|
168
|
+
set_pretty_format_mask %(%s.%s.%s.%s)
|
169
|
+
|
170
|
+
set_generator_numbers (0..9).to_a
|
171
|
+
end
|
172
|
+
|
173
|
+
MyDocument.obtain_verify_digits_positions # [8, 11]
|
174
|
+
# document number without check digits
|
175
|
+
MyDocument.calculate_verify_digits("110.042.49.11")
|
176
|
+
# => [1, 3]
|
177
|
+
document = MyDocument.append_verify_digits("110.042.49.11")
|
178
|
+
# => "110042491113"
|
179
|
+
MyDocument.pretty(document)
|
180
|
+
# => "110.042.491.113"
|
181
|
+
MyDocument.remove_verify_digits!(document)
|
182
|
+
# => [1, 3]
|
183
|
+
document
|
184
|
+
# => "1100424911"
|
185
|
+
document = MyDocument.append_verify_digits(document)
|
186
|
+
# => "110042491113"
|
187
|
+
MyDocument.pretty(document)
|
188
|
+
# => "110.042.491.113"
|
189
|
+
# document number with check digits in the right positions(8, 11)
|
190
|
+
MyDocument.valid?("110.042.491.113")
|
191
|
+
# => true
|
192
|
+
# document number with wrong check digits in the right positions
|
193
|
+
MyDocument.valid?("110.042.492.113")
|
194
|
+
# => false
|
195
|
+
MyDocument.pretty(MyDocument.append_verify_digits("110.042.49.11"))
|
196
|
+
# => "110.042.491.113"
|
197
|
+
```
|
198
|
+
|
199
|
+
---
|
200
|
+
|
114
201
|
## Development
|
115
202
|
|
116
203
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
117
204
|
|
118
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
205
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
119
206
|
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
120
207
|
|
121
208
|
## Contributing
|
122
209
|
|
123
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/fidelisrafael/digit_checksum.
|
210
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fidelisrafael/digit_checksum.
|
124
211
|
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
125
212
|
|
126
213
|
|
127
214
|
## License
|
128
215
|
|
129
216
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
130
|
-
|
data/examples/brazilian_cnpj.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
class CNPJ < DigitChecksum::BaseDocument
|
2
|
-
|
3
|
-
|
2
|
+
set_verify_digits_weights first: %w(5 4 3 2 9 8 7 6 5 4 3 2),
|
3
|
+
second: %w(6 5 4 3 2 9 8 7 6 5 4 3 2)
|
4
4
|
|
5
5
|
# MOD 11
|
6
|
-
|
6
|
+
set_division_factor_modulo 11
|
7
7
|
|
8
8
|
# remove any non digit from document number
|
9
|
-
|
9
|
+
set_clear_number_regexp %r{[^(\d+)]}
|
10
10
|
|
11
11
|
# match format such as: 99.999.999/9999-99 | 99-999-999/9999-99 | 99999999/999999 | 99999999999999
|
12
|
-
|
12
|
+
set_valid_format_regexp %r{(\d{2})[-.]?(\d{3})[-.]?(\d{3})[\/]?(\d{4})[-.]?(\d{2})}
|
13
13
|
|
14
|
-
|
14
|
+
set_pretty_format_mask %(%s.%s.%s/%s-%s)
|
15
15
|
|
16
16
|
# numbers sampled to generate new document numbers
|
17
|
-
|
17
|
+
set_generator_numbers (0..9).to_a
|
18
18
|
end
|
19
19
|
|
20
20
|
CNPJ.generate
|
data/examples/brazilian_cpf.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
class CPF < DigitChecksum::BaseDocument
|
2
|
-
|
3
|
-
|
2
|
+
set_verify_digits_weights first: %w(10 9 8 7 6 5 4 3 2),
|
3
|
+
second: %w(11 10 9 8 7 6 5 4 3 2)
|
4
4
|
|
5
5
|
# MOD 11
|
6
|
-
|
6
|
+
set_division_factor_modulo 11
|
7
7
|
|
8
8
|
# remove any non digit from document number
|
9
|
-
|
9
|
+
set_clear_number_regexp %r{[^(\d+)]}
|
10
10
|
|
11
11
|
# match format such as: 999.999.999-99 | 999-999-999-99 | 99999999999
|
12
|
-
|
12
|
+
set_valid_format_regexp %r{(\d{3})[-.]?(\d{3})[-.]?(\d{3})[-.]?(\d{2})}
|
13
13
|
|
14
|
-
|
14
|
+
set_pretty_format_mask %(%s.%s.%s-%s)
|
15
15
|
|
16
16
|
# numbers sampled to generate new document numbers
|
17
|
-
|
17
|
+
set_generator_numbers (0..9).to_a
|
18
18
|
end
|
19
19
|
|
20
20
|
CPF.generate
|
data/examples/h4ck.rb
CHANGED
@@ -12,24 +12,24 @@ class H4ck < DigitChecksum::BaseDocument
|
|
12
12
|
|
13
13
|
PROGRAMMINGS_LANGUAGES.default = 'Unknown'
|
14
14
|
|
15
|
-
|
15
|
+
set_division_factor_modulo 11
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
set_verify_digits_weights first: %w(17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2),
|
18
|
+
second: %w(18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2),
|
19
|
+
last: %w(19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2)
|
20
20
|
|
21
21
|
# remove any non digit and 0x character from document number
|
22
|
-
|
22
|
+
set_clear_number_regexp %r{(0x)|[^\d+]}
|
23
23
|
|
24
24
|
# 0101&&1111(0x01)||[16]<07>!29
|
25
25
|
# Ex: 0101&&1111(0x01)||[16]<07>!29-110
|
26
|
-
|
26
|
+
set_valid_format_regexp %r{(\d{4})(\d{4})\(?[0x]?(\d{2})\)?\|?\|?\[?(\d{2})\]?\<?(\d{2})\>?\!?(\d{2})\-?(\d{3})}
|
27
27
|
|
28
28
|
# XXXX&&XXXX(0xZZ)||[YY]<MM>!DD-VVV;
|
29
|
-
|
29
|
+
set_pretty_format_mask %(%s&&%s(0x%s)||[%s]<%s>!%s-%s;)
|
30
30
|
|
31
31
|
# numbers sampled to generate new document numbers
|
32
|
-
|
32
|
+
set_generator_numbers (0..9).to_a
|
33
33
|
|
34
34
|
def self.favorite_language(document_number)
|
35
35
|
document_number = normalize_document_number(document_number)
|
@@ -2,22 +2,38 @@ module DigitChecksum
|
|
2
2
|
class BaseDocument
|
3
3
|
|
4
4
|
CONSTANTS_MAP = [
|
5
|
-
:
|
5
|
+
:root_documents_digits_count,
|
6
|
+
:verify_digits_positions,
|
7
|
+
:digits_ignore_positions,
|
6
8
|
:division_factor_modulo,
|
7
|
-
:
|
9
|
+
:verify_digits_weights,
|
8
10
|
:clear_number_regexp,
|
11
|
+
:valid_format_regexp,
|
9
12
|
:pretty_format_mask,
|
10
|
-
:generator_numbers
|
13
|
+
:generator_numbers,
|
14
|
+
:document_length
|
11
15
|
]
|
12
16
|
|
13
17
|
class << self
|
14
18
|
def generate(formatted = true)
|
15
|
-
|
16
|
-
|
19
|
+
document_number = append_verify_digits(generate_root_numbers)
|
20
|
+
|
21
|
+
formatted ? pretty_formatted(document_number) : document_number
|
22
|
+
end
|
17
23
|
|
18
|
-
|
24
|
+
def append_verify_digits(document_number)
|
25
|
+
document_number = normalize_number(document_number)
|
26
|
+
verify_digits = calculate_verify_digits(document_number)
|
27
|
+
|
28
|
+
obtain_verify_digits_positions.each_with_index {|position, index|
|
29
|
+
document_number.insert(position + index, verify_digits.shift)
|
30
|
+
}
|
31
|
+
|
32
|
+
normalize_number_to_s(document_number.compact)
|
33
|
+
end
|
19
34
|
|
20
|
-
|
35
|
+
def generate_root_numbers
|
36
|
+
root_document_digits_count.times.map { get_generator_numbers.sample }
|
21
37
|
end
|
22
38
|
|
23
39
|
def valid?(document_number)
|
@@ -28,13 +44,36 @@ module DigitChecksum
|
|
28
44
|
return false if normalized_document.nil? || normalized_document.empty?
|
29
45
|
|
30
46
|
# if document dont match the exact size, it's invalid
|
31
|
-
return false unless valid_length?(
|
47
|
+
return false unless valid_length?(normalized_document)
|
32
48
|
|
33
|
-
# remove
|
34
|
-
|
49
|
+
# remove verify digits to be verified
|
50
|
+
verify_digits = remove_verify_digits!(normalized_document)
|
51
|
+
|
52
|
+
# calculate the new digits based on root document number
|
35
53
|
digits = calculate_verify_digits(normalized_document)
|
36
54
|
|
37
|
-
|
55
|
+
verify_digits == digits
|
56
|
+
end
|
57
|
+
|
58
|
+
def remove_verify_digits!(document_number)
|
59
|
+
document_number.to_s.gsub!(get_clear_number_regexp, '')
|
60
|
+
|
61
|
+
obtain_verify_digits_positions.each_with_index.flat_map {|position, index|
|
62
|
+
document_number.slice!((position - index), 1)
|
63
|
+
}.map(&:to_i)
|
64
|
+
end
|
65
|
+
|
66
|
+
def obtain_verify_digits_positions
|
67
|
+
begin
|
68
|
+
get_verify_digits_positions
|
69
|
+
# when value its not set
|
70
|
+
rescue NameError => e
|
71
|
+
default_verify_digits_position
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def default_verify_digits_position
|
76
|
+
verify_digits_count.times.map {|i| root_document_digits_count + i }
|
38
77
|
end
|
39
78
|
|
40
79
|
def invalid?(document_number)
|
@@ -44,23 +83,28 @@ module DigitChecksum
|
|
44
83
|
def calculate_verify_digits(document_number)
|
45
84
|
return [] unless correct_length_based_on_first_mask?(document_number)
|
46
85
|
|
86
|
+
document_number = normalize_number(document_number)
|
47
87
|
division_modulo = get_division_factor_modulo
|
88
|
+
digits_positions = obtain_verify_digits_positions.dup
|
48
89
|
digits = []
|
49
90
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
verify_digit = calculate_verify_digit(
|
91
|
+
get_verify_digits_weights.each_with_index do |data, index|
|
92
|
+
position, mask = *data
|
93
|
+
current_document = root_document_number(document_number, mask)
|
94
|
+
verify_digit = calculate_verify_digit(current_document, mask, division_modulo)
|
54
95
|
|
55
96
|
digits << verify_digit
|
56
|
-
|
97
|
+
digit_position = digits_positions.shift + index
|
98
|
+
|
99
|
+
# just update ref
|
100
|
+
document_number.insert(digit_position, verify_digit)
|
57
101
|
end
|
58
102
|
|
59
103
|
digits
|
60
104
|
end
|
61
105
|
|
62
106
|
def root_document_number(document_number, mask = nil)
|
63
|
-
mask ||=
|
107
|
+
mask ||= get_verify_digits_weights.values[0]
|
64
108
|
|
65
109
|
normalize_document_number(document_number, mask.size)
|
66
110
|
end
|
@@ -84,9 +128,11 @@ module DigitChecksum
|
|
84
128
|
end
|
85
129
|
|
86
130
|
def pretty_formatted(document_number)
|
87
|
-
|
131
|
+
normalized_doc = normalize_number_to_s(document_number)
|
132
|
+
|
133
|
+
return "" if normalized_doc.empty?
|
88
134
|
|
89
|
-
numbers =
|
135
|
+
numbers = normalized_doc.to_s.scan(get_valid_format_regexp).flatten
|
90
136
|
|
91
137
|
# document has a value but it's not valid
|
92
138
|
return "" if numbers.empty?
|
@@ -103,11 +149,16 @@ module DigitChecksum
|
|
103
149
|
def calculate_digits_data(document_number, mask, division_factor)
|
104
150
|
sum = calculate_digits_sum(document_number, mask)
|
105
151
|
quotient = (sum / division_factor)
|
106
|
-
|
152
|
+
|
153
|
+
rest = calculate_digits_sum_rest(sum, quotient, division_factor)
|
107
154
|
|
108
155
|
{ sum: sum, quotient: quotient, rest: rest, verify_digit: digit_verify(rest, division_factor) }
|
109
156
|
end
|
110
157
|
|
158
|
+
def calculate_digits_sum_rest(sum, quotient, division_factor)
|
159
|
+
(sum % division_factor)
|
160
|
+
end
|
161
|
+
|
111
162
|
def calculate_digits_sum(document_number, mask)
|
112
163
|
normalized_document_number = normalize_document_number(document_number)
|
113
164
|
|
@@ -122,15 +173,19 @@ module DigitChecksum
|
|
122
173
|
end
|
123
174
|
|
124
175
|
def first_verify_mask
|
125
|
-
|
176
|
+
get_verify_digits_weights.values[0]
|
126
177
|
end
|
127
178
|
|
128
179
|
def verify_digits_count
|
129
|
-
|
180
|
+
get_verify_digits_weights.size
|
130
181
|
end
|
131
182
|
|
132
183
|
def root_document_digits_count
|
133
|
-
|
184
|
+
begin
|
185
|
+
get_root_documents_digits_count
|
186
|
+
rescue NameError => e
|
187
|
+
first_verify_mask.size
|
188
|
+
end
|
134
189
|
end
|
135
190
|
|
136
191
|
def correct_length_based_on_first_mask?(document_number)
|
@@ -148,17 +203,13 @@ module DigitChecksum
|
|
148
203
|
alias :formatted :pretty_formatted
|
149
204
|
alias :pretty :pretty_formatted
|
150
205
|
|
151
|
-
CONSTANTS_MAP.each do |
|
152
|
-
define_method "get_#{
|
153
|
-
const_name
|
154
|
-
|
155
|
-
self.const_get(const_identifier.upcase)
|
206
|
+
CONSTANTS_MAP.each do |const_name|
|
207
|
+
define_method "get_#{const_name}" do
|
208
|
+
self.const_get(const_name.to_s.upcase)
|
156
209
|
end
|
157
210
|
|
158
|
-
define_method
|
159
|
-
const_name
|
160
|
-
|
161
|
-
self.const_set(const_name, arg)
|
211
|
+
define_method "set_#{const_name}" do |value|
|
212
|
+
self.const_set(const_name.to_s.upcase, value)
|
162
213
|
end
|
163
214
|
end
|
164
215
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: digit_checksum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Fidelis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|