egn 1.1.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b592e6bdef03c4501e6ded89bcb6a5189c74653
4
- data.tar.gz: be42449680d204b7498944fb1a4ce5c67a3e8375
3
+ metadata.gz: c50e9550220d451fd878ef94ef66a035d040ef2d
4
+ data.tar.gz: 0c4120ed1258d8e2ce27327dc2b4267d23152106
5
5
  SHA512:
6
- metadata.gz: de32cb6efa8e5636232a318277ea58d00d1042bfe8da6ff818974f2799b4b5af1aebef926b29d65bd64e80baf2e66e01095c1c76fadfa1897b7a23ae623c701b
7
- data.tar.gz: 633fdd168f71d7619ce2d17122c1172f051d72e6e82e38119b538cd43c11ce45f91464facf256b5d2560a63e0681465175dadd83aa516821b4541b6ee7b4fd67
6
+ metadata.gz: 48c9632edb348b3f00872c0fb12a41230c031c75bf7788d19f95ac08398e5b2b8555c0cc7e63ffce757d4593c19588a31a15fcbdb179a98b5abe23fcb0c35c67
7
+ data.tar.gz: 19cb7bbc9e23fba5ba47f6b1489ce1a9722b5e88aed4606f907105cb5392e40c369e16fdb42b5a2d14b85568e7618aef0f019ab1bd5e45bae15c4d56463aa694
data/lib/egn/generator.rb CHANGED
@@ -32,6 +32,7 @@ module Egn
32
32
  raise ArgumentError, "Year out of bounds" unless (1800..2099).include?(options[:year])
33
33
  raise ArgumentError, "Month out of bounds" unless (1..12).include?(options[:month])
34
34
  raise ArgumentError, "Day out of bounds" unless (1..31).include?(options[:day])
35
+ raise ArgumentError, "Invalid sex; valid values: [:male, :female]" unless [:male, :female].include?(options[:sex])
35
36
  end
36
37
 
37
38
  def defaults
@@ -39,7 +40,8 @@ module Egn
39
40
  {
40
41
  year: date.year,
41
42
  month: date.month,
42
- day: date.day
43
+ day: date.day,
44
+ sex: [:male, :female].sample
43
45
  }
44
46
  end
45
47
 
@@ -47,16 +49,15 @@ module Egn
47
49
  # Get random century, region and sex
48
50
  options[:century] = options[:year] - (options[:year] % 100)
49
51
  options[:region] = Random.rand(0..999)
50
- options[:sex] = Random.rand(1..2)
51
52
 
52
53
  # Recalculate month based on the century
53
54
  options[:month] += 20 if options[:century] == 1800
54
55
  options[:month] += 40 if options[:century] == 2000
55
56
 
56
57
  # Recalculate region based on sex
57
- if options[:sex] == 1 && options[:region].odd?
58
+ if options[:sex] == :male && options[:region].odd?
58
59
  options[:region] -= 1
59
- elsif options[:sex] == 2 && options[:region].even?
60
+ elsif options[:sex] == :female && options[:region].even?
60
61
  options[:region] += 1
61
62
  end
62
63
 
data/lib/egn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Egn
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -22,7 +22,7 @@ describe Egn::Generator do
22
22
 
23
23
  context "invoked with arguments" do
24
24
  it "generates a new EGN considering the given options" do
25
- number = Egn::Generator.generate(year: 1990, month: 12, day: 30, sex: :m)
25
+ number = Egn::Generator.generate(year: 1990, month: 12, day: 30, sex: :male)
26
26
  egn = Egn::Egn.new(number)
27
27
 
28
28
  expect(egn).to be_valid
@@ -49,16 +49,29 @@ describe Egn::Generator do
49
49
  expect(egn.day).to eq(15)
50
50
  end
51
51
 
52
+ it "generates female EGNs" do
53
+ number = Egn::Generator.generate(sex: :female)
54
+ egn = Egn::Egn.new(number)
55
+
56
+ expect(egn.sex).to eq(:female)
57
+ end
58
+
59
+ it "generates male EGNs" do
60
+ number = Egn::Generator.generate(sex: :male)
61
+ egn = Egn::Egn.new(number)
62
+
63
+ expect(egn.sex).to eq(:male)
64
+ end
65
+
52
66
  it "validates the options" do
53
67
 
54
- options = {year: 1960, month: 6, day: 3}
68
+ options = {year: 1960, month: 6, day: 3, sex: :male}
55
69
 
56
70
  Egn::Generator.any_instance.should_receive(:validate!).with(options)
57
71
 
58
72
  Egn::Generator.generate(options)
59
73
  end
60
74
 
61
-
62
75
  end
63
76
  end
64
77
 
@@ -82,6 +95,12 @@ describe Egn::Generator do
82
95
  }.to raise_error ArgumentError
83
96
  end
84
97
 
98
+ it "raises an exception if invalid sex is given" do
99
+ expect{
100
+ Egn::Generator.generate(sex: :none)
101
+ }.to raise_error ArgumentError
102
+ end
103
+
85
104
  end
86
105
 
87
106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gmitrev