age_jp 0.0.6 → 0.1.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/age_jp.gemspec +1 -2
- data/lib/age_jp/version.rb +1 -1
- data/spec/age_jp_spec.rb +93 -119
- data/spec/spec_helper.rb +5 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af033357d3a9ea266f503d39bdc810eaa7e09945
|
4
|
+
data.tar.gz: 2de6d0ea776b76b9712283e0cd19cbf7d79a1016
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8f403ea6dc966834c8f2866c18ae4881f817f1975c41199fcd38eed53037d0ae8e93c4fad728cfda2d49ea82c1a80bbdadb08be64fa24be272e90283c41efd7
|
7
|
+
data.tar.gz: eadb95a34a6164e41bf5294af1eaf85964fdf4a0095231f888940c874c93e8feb658626c5051282603c09aa1b824fa234e4a3bd1d855c18db1cc5d4431073754
|
data/age_jp.gemspec
CHANGED
@@ -18,10 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "activesupport", '>=
|
21
|
+
spec.add_dependency "activesupport", '>= 4.1'
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", ">= 1.0"
|
24
24
|
spec.add_development_dependency "rake", ">= 10.0"
|
25
25
|
spec.add_development_dependency "rspec", '~> 3.0'
|
26
|
-
spec.add_development_dependency "timecop"
|
27
26
|
end
|
data/lib/age_jp/version.rb
CHANGED
data/spec/age_jp_spec.rb
CHANGED
@@ -3,221 +3,205 @@ require 'spec_helper'
|
|
3
3
|
describe AgeJp do
|
4
4
|
describe '#age' do
|
5
5
|
context "birthday is 2000/01/01. " do
|
6
|
+
around do |example|
|
7
|
+
travel_to(current_date) { example.run }
|
8
|
+
end
|
9
|
+
|
6
10
|
let(:birthday) { Date.new(2000, 1, 1) }
|
7
|
-
subject
|
11
|
+
subject { birthday.age }
|
8
12
|
|
9
13
|
context 'when today is 2014/12/30' do
|
10
|
-
|
11
|
-
|
12
|
-
it { expect(age).to eq 14 }
|
14
|
+
let(:current_date) { Date.new(2014, 12, 30) }
|
15
|
+
it { is_expected.to eq 14 }
|
13
16
|
end
|
14
17
|
|
15
18
|
context 'when today is 2014/12/31' do
|
16
|
-
|
17
|
-
|
18
|
-
it { expect(age).to eq 14 }
|
19
|
+
let(:current_date) { Date.new(2014, 12, 31) }
|
20
|
+
it { is_expected.to eq 14 }
|
19
21
|
end
|
20
22
|
|
21
23
|
context 'when today is 2015/1/1' do
|
22
|
-
|
23
|
-
|
24
|
-
it { expect(age).to eq 15 }
|
24
|
+
let(:current_date) { Date.new(2015, 1, 1) }
|
25
|
+
it { is_expected.to eq 15 }
|
25
26
|
end
|
26
|
-
|
27
|
-
after { Timecop.return }
|
28
27
|
end
|
29
28
|
|
30
29
|
context "birthday is 2000/02/29. " do
|
30
|
+
around do |example|
|
31
|
+
travel_to(current_date) { example.run }
|
32
|
+
end
|
33
|
+
|
31
34
|
let(:birthday) { Date.new(2000, 2, 29) }
|
32
|
-
subject
|
35
|
+
subject { birthday.age }
|
33
36
|
|
34
37
|
context 'when today is 2015/02/28' do
|
35
|
-
|
36
|
-
|
37
|
-
it { expect(age).to eq 15 }
|
38
|
+
let(:current_date) { Date.new(2015, 2, 28) }
|
39
|
+
it { is_expected.to eq 15 }
|
38
40
|
end
|
39
41
|
|
40
42
|
context 'when today is 2016/02/28' do
|
41
|
-
|
42
|
-
|
43
|
-
it { expect(age).to eq 15 }
|
43
|
+
let(:current_date) { Date.new(2016, 2, 28) }
|
44
|
+
it { is_expected.to eq 15 }
|
44
45
|
end
|
45
46
|
|
46
47
|
context 'when today is 2016/2/29' do
|
47
|
-
|
48
|
-
|
49
|
-
it { expect(age).to eq 16 }
|
48
|
+
let(:current_date) { Date.new(2016, 2, 29) }
|
49
|
+
it { is_expected.to eq 16 }
|
50
50
|
end
|
51
|
-
|
52
|
-
after { Timecop.return }
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
56
54
|
describe '#age_at' do
|
57
55
|
context "birthday is 2000/01/01. " do
|
58
56
|
let(:birthday) { Date.new(2000, 1, 1) }
|
59
|
-
subject
|
57
|
+
subject { birthday.age_at(today) }
|
60
58
|
|
61
59
|
context 'when date is 2016/12/30' do
|
62
60
|
let(:today) { Date.new(2016, 12, 30) }
|
63
|
-
|
64
|
-
it { expect(age_at).to eq 16 }
|
61
|
+
it { is_expected.to eq 16 }
|
65
62
|
end
|
66
63
|
|
67
64
|
context 'when date is 2016/12/31' do
|
68
65
|
let(:today) { Date.new(2016, 12, 31) }
|
69
|
-
|
70
|
-
it { expect(age_at).to eq 16 }
|
66
|
+
it { is_expected.to eq 16 }
|
71
67
|
end
|
72
68
|
|
73
69
|
context 'when date is 2017/1/1' do
|
74
70
|
let(:today) { Date.new(2017, 1, 1) }
|
75
|
-
|
76
|
-
it { expect(age_at).to eq 17 }
|
71
|
+
it { is_expected.to eq 17 }
|
77
72
|
end
|
78
73
|
end
|
79
74
|
|
80
75
|
context 'invalid date' do
|
81
76
|
let(:birthday) { Date.new(2000, 1, 1) }
|
82
77
|
let(:invalid_date) { 'String' }
|
83
|
-
subject
|
78
|
+
subject { birthday.age_at(invalid_date) }
|
84
79
|
|
85
|
-
it { expect { subject }.to raise_error(/invalid date/) }
|
80
|
+
it { expect { subject }.to raise_error(ArgumentError, /invalid date/) }
|
86
81
|
end
|
87
82
|
end
|
88
83
|
|
89
84
|
describe '#age_jp' do
|
90
85
|
context "birthday is 2000/01/01. " do
|
86
|
+
around do |example|
|
87
|
+
travel_to(current_date) { example.run }
|
88
|
+
end
|
89
|
+
|
91
90
|
let(:birthday) { Date.new(2000, 1, 1) }
|
92
|
-
subject
|
91
|
+
subject { birthday.age_jp }
|
93
92
|
|
94
93
|
context 'when today is 2014/12/30' do
|
95
|
-
|
96
|
-
|
97
|
-
it { expect(age_jp).to eq 14 }
|
94
|
+
let(:current_date) { Date.new(2014, 12, 30) }
|
95
|
+
it { is_expected.to eq 14 }
|
98
96
|
end
|
99
97
|
|
100
98
|
context 'when today is 2014/12/31' do
|
101
|
-
|
102
|
-
|
103
|
-
it { expect(age_jp).to eq 15 }
|
99
|
+
let(:current_date) { Date.new(2014, 12, 31) }
|
100
|
+
it { is_expected.to eq 15 }
|
104
101
|
end
|
105
102
|
|
106
103
|
context 'when today is 2015/1/1' do
|
107
|
-
|
108
|
-
|
109
|
-
it { expect(age_jp).to eq 15 }
|
104
|
+
let(:current_date) { Date.new(2015, 1, 1) }
|
105
|
+
it { is_expected.to eq 15 }
|
110
106
|
end
|
111
|
-
|
112
|
-
after { Timecop.return }
|
113
107
|
end
|
114
108
|
|
115
109
|
context "birthday is 2000/02/29. " do
|
110
|
+
around do |example|
|
111
|
+
travel_to(current_date) { example.run }
|
112
|
+
end
|
113
|
+
|
116
114
|
let(:birthday) { Date.new(2000, 2, 29) }
|
117
|
-
subject
|
115
|
+
subject { birthday.age_jp }
|
118
116
|
|
119
117
|
context 'when today is 2015/02/27' do
|
120
|
-
|
121
|
-
|
122
|
-
it { expect(age_jp).to eq 14 }
|
118
|
+
let(:current_date) { Date.new(2015, 2, 27) }
|
119
|
+
it { is_expected.to eq 14 }
|
123
120
|
end
|
124
121
|
|
125
122
|
context 'when today is 2015/02/28' do
|
126
|
-
|
127
|
-
|
128
|
-
it { expect(age_jp).to eq 15 }
|
123
|
+
let(:current_date) { Date.new(2015, 2, 28) }
|
124
|
+
it { is_expected.to eq 15 }
|
129
125
|
end
|
130
126
|
|
131
127
|
context 'when today is 2016/02/28' do
|
132
|
-
|
133
|
-
|
134
|
-
it { expect(age_jp).to eq 16 }
|
128
|
+
let(:current_date) { Date.new(2016, 2, 28) }
|
129
|
+
it { is_expected.to eq 16 }
|
135
130
|
end
|
136
131
|
|
137
132
|
context 'when today is 2016/2/29' do
|
138
|
-
|
139
|
-
|
140
|
-
it { expect(age_jp).to eq 16 }
|
133
|
+
let(:current_date) { Date.new(2016, 2, 29) }
|
134
|
+
it { is_expected.to eq 16 }
|
141
135
|
end
|
142
|
-
|
143
|
-
after { Timecop.return }
|
144
136
|
end
|
145
137
|
end
|
146
138
|
|
147
139
|
describe '#age_jp_at' do
|
148
140
|
context "birthday is 2000/01/01. " do
|
149
141
|
let(:birthday) { Date.new(2000, 1, 1) }
|
150
|
-
subject
|
142
|
+
subject { birthday.age_jp_at(today) }
|
151
143
|
|
152
144
|
context 'when date is 2016/12/30' do
|
153
145
|
let(:today) { Date.new(2016, 12, 30) }
|
154
|
-
|
155
|
-
it { expect(age_jp_at).to eq 16 }
|
146
|
+
it { is_expected.to eq 16 }
|
156
147
|
end
|
157
148
|
|
158
149
|
context 'when date is 2016/12/31' do
|
159
150
|
let(:today) { Date.new(2016, 12, 31) }
|
160
|
-
|
161
|
-
it { expect(age_jp_at).to eq 17 }
|
151
|
+
it { is_expected.to eq 17 }
|
162
152
|
end
|
163
153
|
|
164
154
|
context 'when date is 2017/1/1' do
|
165
155
|
let(:today) { Date.new(2017, 1, 1) }
|
166
|
-
|
167
|
-
it { expect(age_jp_at).to eq 17 }
|
156
|
+
it { is_expected.to eq 17 }
|
168
157
|
end
|
169
158
|
end
|
170
159
|
end
|
171
160
|
|
172
161
|
describe '#east_asian_age_reckoning' do
|
173
162
|
context "birthday is 1999/12/31. " do
|
174
|
-
|
163
|
+
around do |example|
|
164
|
+
travel_to(current_date) { example.run }
|
165
|
+
end
|
175
166
|
|
176
|
-
|
167
|
+
let(:birthday) { Date.new(1999, 12, 31) }
|
168
|
+
subject { birthday.east_asian_age_reckoning }
|
177
169
|
|
178
170
|
context 'when today is 1999/12/31' do
|
179
|
-
|
180
|
-
|
181
|
-
it { expect(east_asian_age_reckoning).to eq 1 }
|
171
|
+
let(:current_date) { Date.new(1999, 12, 31) }
|
172
|
+
it { is_expected.to eq 1 }
|
182
173
|
end
|
183
174
|
|
184
175
|
context 'when today is 2000/01/01' do
|
185
|
-
|
186
|
-
|
187
|
-
it { expect(east_asian_age_reckoning).to eq 2 }
|
176
|
+
let(:current_date) { Date.new(2000, 1, 1) }
|
177
|
+
it { is_expected.to eq 2 }
|
188
178
|
end
|
189
179
|
|
190
180
|
context 'when today is 2000/12/31' do
|
191
|
-
|
192
|
-
|
193
|
-
it { expect(east_asian_age_reckoning).to eq 2 }
|
181
|
+
let(:current_date) { Date.new(2000, 12, 31) }
|
182
|
+
it { is_expected.to eq 2 }
|
194
183
|
end
|
195
|
-
|
196
|
-
after { Timecop.return }
|
197
184
|
end
|
198
185
|
end
|
199
186
|
|
200
187
|
describe '#east_asian_age_reckoning_at' do
|
201
188
|
context "birthday is 1999/12/31. " do
|
202
189
|
let(:birthday) { Date.new(1999, 12, 31) }
|
203
|
-
subject
|
190
|
+
subject { birthday.east_asian_age_reckoning_at(today) }
|
204
191
|
|
205
192
|
context 'when date is 2016/12/31' do
|
206
193
|
let(:today) { Date.new(2016, 12, 31) }
|
207
|
-
|
208
|
-
it { expect(east_asian_age_reckoning_at).to eq 18 }
|
194
|
+
it { is_expected.to eq 18 }
|
209
195
|
end
|
210
196
|
|
211
197
|
context 'when date is 2017/01/01' do
|
212
198
|
let(:today) { Date.new(2017, 1, 1) }
|
213
|
-
|
214
|
-
it { expect(east_asian_age_reckoning_at).to eq 19 }
|
199
|
+
it { is_expected.to eq 19 }
|
215
200
|
end
|
216
201
|
|
217
202
|
context 'when date is 2017/12/31' do
|
218
203
|
let(:today) { Date.new(2017, 12, 31) }
|
219
|
-
|
220
|
-
it { expect(east_asian_age_reckoning_at).to eq 19 }
|
204
|
+
it { is_expected.to eq 19 }
|
221
205
|
end
|
222
206
|
end
|
223
207
|
end
|
@@ -230,13 +214,11 @@ describe AgeJp do
|
|
230
214
|
|
231
215
|
context 'with year is 16' do
|
232
216
|
let(:year) { 16 }
|
233
|
-
|
234
217
|
it { is_expected.to eq Date.new(2016, 1, 1) }
|
235
218
|
end
|
236
219
|
|
237
220
|
context 'with year is 17' do
|
238
221
|
let(:year) { 17 }
|
239
|
-
|
240
222
|
it { is_expected.to eq Date.new(2017, 1, 1) }
|
241
223
|
end
|
242
224
|
end
|
@@ -246,13 +228,11 @@ describe AgeJp do
|
|
246
228
|
|
247
229
|
context 'with year is 16' do
|
248
230
|
let(:year) { 16 }
|
249
|
-
|
250
231
|
it { is_expected.to eq Date.new(2016, 2, 29) }
|
251
232
|
end
|
252
233
|
|
253
234
|
context 'with year is 17' do
|
254
235
|
let(:year) { 17 }
|
255
|
-
|
256
236
|
it { is_expected.to eq Date.new(2017, 2, 28) }
|
257
237
|
end
|
258
238
|
end
|
@@ -266,13 +246,11 @@ describe AgeJp do
|
|
266
246
|
|
267
247
|
context 'with year is 16' do
|
268
248
|
let(:year) { 16 }
|
269
|
-
|
270
249
|
it { is_expected.to eq Date.new(2015, 12, 31) }
|
271
250
|
end
|
272
251
|
|
273
252
|
context 'with year is 17' do
|
274
253
|
let(:year) { 17 }
|
275
|
-
|
276
254
|
it { is_expected.to eq Date.new(2016, 12, 31) }
|
277
255
|
end
|
278
256
|
end
|
@@ -282,13 +260,11 @@ describe AgeJp do
|
|
282
260
|
|
283
261
|
context 'with year is 16' do
|
284
262
|
let(:year) { 16 }
|
285
|
-
|
286
263
|
it { is_expected.to eq Date.new(2016, 2, 28) }
|
287
264
|
end
|
288
265
|
|
289
266
|
context 'with year is 17' do
|
290
267
|
let(:year) { 17 }
|
291
|
-
|
292
268
|
it { is_expected.to eq Date.new(2017, 2, 28) }
|
293
269
|
end
|
294
270
|
end
|
@@ -296,53 +272,51 @@ describe AgeJp do
|
|
296
272
|
|
297
273
|
describe '#insurance_age' do
|
298
274
|
context "birthday is 2000/01/01. " do
|
275
|
+
around do |example|
|
276
|
+
travel_to(current_date) { example.run }
|
277
|
+
end
|
278
|
+
|
299
279
|
let(:birthday) { Date.new(2000, 1, 1) }
|
300
|
-
subject
|
280
|
+
subject { birthday.insurance_age }
|
301
281
|
|
302
282
|
context 'when today is 2015/01/01' do
|
303
|
-
|
304
|
-
|
305
|
-
it { expect(insurance_age).to eq 15 }
|
283
|
+
let(:current_date) { Date.new(2015, 1, 1) }
|
284
|
+
it { is_expected.to eq 15 }
|
306
285
|
end
|
307
286
|
|
308
287
|
context 'when today is 2015/07/31' do
|
309
|
-
|
310
|
-
|
311
|
-
it { expect(insurance_age).to eq 15 }
|
288
|
+
let(:current_date) { Date.new(2015, 7, 31) }
|
289
|
+
it { is_expected.to eq 15 }
|
312
290
|
end
|
313
291
|
|
314
292
|
context 'when today is 2015/08/01' do
|
315
|
-
|
316
|
-
|
317
|
-
it { expect(insurance_age).to eq 16 }
|
293
|
+
let(:current_date) { Date.new(2015, 8, 1) }
|
294
|
+
it { is_expected.to eq 16 }
|
318
295
|
end
|
319
|
-
|
320
|
-
after { Timecop.return }
|
321
296
|
end
|
322
297
|
|
323
298
|
context "birthday is 2000/07/31. " do
|
299
|
+
around do |example|
|
300
|
+
travel_to(current_date) { example.run }
|
301
|
+
end
|
302
|
+
|
324
303
|
let(:birthday) { Date.new(2000, 7, 31) }
|
325
|
-
subject
|
304
|
+
subject { birthday.insurance_age }
|
326
305
|
|
327
306
|
context 'when today is 2016/02/28' do
|
328
|
-
|
329
|
-
|
330
|
-
it { expect(insurance_age).to eq 15 }
|
307
|
+
let(:current_date) { Date.new(2016, 2, 28) }
|
308
|
+
it { is_expected.to eq 15 }
|
331
309
|
end
|
332
310
|
|
333
311
|
context 'when today is 2016/02/29' do
|
334
|
-
|
335
|
-
|
336
|
-
it { expect(insurance_age).to eq 16 }
|
312
|
+
let(:current_date) { Date.new(2016, 2, 29) }
|
313
|
+
it { is_expected.to eq 16 }
|
337
314
|
end
|
338
315
|
|
339
316
|
context 'when today is 2016/03/01' do
|
340
|
-
|
341
|
-
|
342
|
-
it { expect(insurance_age).to eq 16 }
|
317
|
+
let(:current_date) { Date.new(2016, 3, 1) }
|
318
|
+
it { is_expected.to eq 16 }
|
343
319
|
end
|
344
|
-
|
345
|
-
after { Timecop.return }
|
346
320
|
end
|
347
321
|
end
|
348
322
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: age_jp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryoff
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: timecop
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
description: A simpel age calculator for a law of Japan.
|
84
70
|
email:
|
85
71
|
- ryoffes@gmail.com
|