egn 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a86c041349bc20394ea046da1a9d4a777dde322b
4
- data.tar.gz: 69a89c71ad2e3d9df349b22af0c0fe6ca0867a71
3
+ metadata.gz: 8cec4b145317730625a2ecf4a0697138901a586d
4
+ data.tar.gz: 68bda640e1e48d67e1d306b172ec08d1e1f42a55
5
5
  SHA512:
6
- metadata.gz: 99c8f0cc69329cc40f4b0898953898554b5ac16614abee4563ffddd6fa6eb9a1e4948a0e72b9f1e944ea054afee2f8fea4c38a4e5165b6a8a487a3d3ef1c9d68
7
- data.tar.gz: 210c8a9827e4bd59e8df12020283642f4d032e69eec08e9e9f0e9df7735fa7ed727024cae1996832fe2d08e726f4d747d598e099098ad6cae25df3d2604ca553
6
+ metadata.gz: 7e20300f2867147ee57fbf0a4a5208e47b2e159f75666df2d800c643fc4b1b737634cfc709c2e9754f9358242c3a8bfe7802d1f8ba31a352fc32c9b06ab843bf
7
+ data.tar.gz: 821ef286a560a0e97ddd3cfe6696725d0747be5ccb20181c266938792bf8ebcc09b84d62ebd22aedacffee88722c96b19bd3fd974550814a958bb5b0094e5b21
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.9.3"
4
- - "2.0.0"
5
- - "2.1.0"
3
+ - "2.2.7"
4
+ - "2.3.4"
5
+ - "2.4.1"
6
6
  script: bundle exec rspec spec
data/README.md CHANGED
@@ -10,9 +10,9 @@ information.
10
10
  ## Installation
11
11
 
12
12
  Add this line to your application's Gemfile:
13
-
14
- gem 'egn'
15
-
13
+ ```ruby
14
+ gem 'egn'
15
+ ```
16
16
  And then execute:
17
17
 
18
18
  $ bundle
@@ -23,51 +23,53 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
- require 'egn'
26
+ ```ruby
27
+ require 'egn'
27
28
 
28
- # Quickly generate a random number
29
- Egn.generate
30
- => '6101047500'
29
+ # Quickly generate a random number
30
+ Egn.generate
31
+ => '6101047500'
31
32
 
32
- # Validate a given number
33
- Egn.validate('6101047500')
34
- => true
33
+ # Validate a given number
34
+ Egn.validate('6101047500')
35
+ => true
35
36
 
36
- # Create an new EGN object with a random number
37
- egn = Egn::Egn.new
38
- => 9212094524
37
+ # Create an new EGN object with a random number
38
+ egn = Egn::Egn.new
39
+ => 9212094524
39
40
 
40
- # OR generate EGN for a specific date
41
- egn = Egn::Egn.new(year: 1945, month: 5, day: 8)
42
- => 4505085346
41
+ # OR generate EGN for a specific date
42
+ egn = Egn::Egn.new(year: 1945, month: 5, day: 8)
43
+ => 4505085346
43
44
 
44
- # OR parse an existing one
45
- egn = Egn.parse('6101047500')
46
- => 6101047500
45
+ # OR parse an existing one
46
+ egn = Egn.parse('6101047500')
47
+ => 6101047500
47
48
 
48
- egn.birth_date
49
- => #<Date: 1961-01-04 ((2437304j,0s,0n),+0s,2299161j)>
49
+ egn.birth_date
50
+ => #<Date: 1961-01-04 ((2437304j,0s,0n),+0s,2299161j)>
50
51
 
51
- egn.year
52
- => 1961
52
+ egn.year
53
+ => 1961
53
54
 
54
- egn.month
55
- => 1
55
+ egn.month
56
+ => 1
56
57
 
57
- egn.day
58
- => 10
58
+ egn.day
59
+ => 10
59
60
 
60
- egn.gender # egn.sex can also be used
61
- => :male
61
+ egn.gender # egn.sex can also be used
62
+ => :male
62
63
 
63
- egn.gender(format: :char)
64
- => 'm'
64
+ egn.gender(format: :char)
65
+ => 'm'
65
66
 
66
- egn.gender(format: :number)
67
- => 1
67
+ egn.gender(format: :number)
68
+ => 1
68
69
 
69
- egn.valid?
70
- => true
70
+ egn.valid?
71
+ => true
72
+ ```
71
73
 
72
74
  ## Contributing
73
75
 
data/lib/egn/util.rb CHANGED
@@ -7,8 +7,8 @@ module Egn
7
7
  # be determined by examining the month.
8
8
  # The rules are as follows:
9
9
  # * For people born in 1900..1999 the month does not change
10
- # * For people born in 1800..1899 the month increases by 20 (e.g January is 21)
11
- # * For people born in 2000..2099 the month increases by 40 (e.g December is 52)
10
+ # * For people born in 1800..1899 the month is increased by 20 (e.g January is 21)
11
+ # * For people born in 2000..2099 the month is increased by 40 (e.g December is 52)
12
12
  def self.determine_date(year, month)
13
13
  case month
14
14
  when (1..12)
@@ -24,7 +24,7 @@ module Egn
24
24
  [year.to_i, month]
25
25
  end
26
26
 
27
- # More information on the formula: http://www.grao.bg/esgraon.html
27
+ # More information on the formula: http://www.grao.bg/esgraon.html#section2
28
28
  def self.egn_checksum(egn)
29
29
  sum = egn.chars.map(&:to_i).zip(WEIGHTS).map { |n| n.reduce(:*) }.reduce(:+)
30
30
 
data/lib/egn/validator.rb CHANGED
@@ -17,6 +17,10 @@ module Egn
17
17
  def validate
18
18
  return false unless @egn.length == 10
19
19
  return false unless Date.valid_date?(@year, @month, @day)
20
+
21
+ # Gregorian calendar adoption in 1916 in Bulgaria
22
+ # 31/03/1916 > +13 days > 14/04/1916
23
+ return false if @year == 1916 && @month == 4 && @day <= 13
20
24
 
21
25
  # Calculate the checksum and check if the given one is correct
22
26
  checksum = Util.egn_checksum(@egn[0, 9])
data/lib/egn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Egn
2
- VERSION = '1.3.3'
2
+ VERSION = '1.3.4'
3
3
  end
@@ -10,6 +10,10 @@ describe Egn::Validator do
10
10
  it 'fails for incorrect dates' do
11
11
  expect(Egn::Validator.validate('6101347500')).to be_false
12
12
  end
13
+
14
+ it 'fails for dates during gregorian calendar adoption' do
15
+ expect(Egn::Validator.validate('1604010886')).to be_false
16
+ end
13
17
 
14
18
  it 'checks 10 000 of the generated numbers' do
15
19
  Array.new(10_000) { |_| Egn.generate }.each do |egn|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - gmitrev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-28 00:00:00.000000000 Z
11
+ date: 2017-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  version: '0'
114
114
  requirements: []
115
115
  rubyforge_project:
116
- rubygems_version: 2.4.5
116
+ rubygems_version: 2.5.2
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: An easy way to generate and validate EGN numbers and parse them for useful