edtf 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +49 -19
- data/edtf.gemspec +1 -1
- data/features/parser/dates.feature +23 -10
- data/features/parser/intervals.feature +1 -1
- data/features/print/level_0_edtf.feature +1 -1
- data/features/print/level_1_edtf.feature +93 -2
- data/features/print/level_2_edtf.feature +31 -0
- data/features/print/uncertain_or_approximate.feature +134 -0
- data/features/step_definitions/edtf_steps.rb +35 -1
- data/lib/edtf.rb +16 -5
- data/lib/edtf/compatibility.rb +5 -16
- data/lib/edtf/date.rb +151 -35
- data/lib/edtf/date_time.rb +5 -5
- data/lib/edtf/interval.rb +243 -44
- data/lib/edtf/parser.y +39 -30
- data/lib/edtf/season.rb +16 -15
- data/lib/edtf/uncertainty.rb +57 -21
- data/lib/edtf/version.rb +1 -1
- data/spec/edtf/date_spec.rb +130 -3
- data/spec/edtf/interval_spec.rb +132 -4
- data/spec/edtf/parser_spec.rb +56 -35
- data/spec/edtf/uncertainty_spec.rb +167 -4
- metadata +20 -16
data/spec/edtf/interval_spec.rb
CHANGED
@@ -1,12 +1,140 @@
|
|
1
1
|
module EDTF
|
2
2
|
describe 'Interval' do
|
3
|
-
|
3
|
+
|
4
|
+
describe 'the interval 2008/2011' do
|
5
|
+
let(:interval) { Date.edtf('2008/2011') }
|
4
6
|
|
5
|
-
|
7
|
+
it { interval.should_not be_open }
|
8
|
+
it { interval.should_not be_open_end }
|
9
|
+
it { interval.should_not be_unknown_start }
|
10
|
+
it { interval.should_not be_unknown_end }
|
11
|
+
|
12
|
+
it 'has a length of 4' do
|
13
|
+
interval.to_a.length.should == 4
|
14
|
+
end
|
15
|
+
|
16
|
+
it '#step(2) yields the years 2008 and 2010' do
|
17
|
+
interval.step(2).map(&:year).should == [2008,2010]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'the max date is 2011-12-31' do
|
21
|
+
interval.max.to_s.should == '2011-12-31'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'the max date has year precision' do
|
25
|
+
interval.max.should be_year_precision
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'the min date is 2008-01-01' do
|
29
|
+
interval.min.to_s.should == '2008-01-01'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'the min date has year precision' do
|
33
|
+
interval.min.should be_year_precision
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
it 'includes the years 2008, 2009, 2010 and 2011' do
|
38
|
+
interval.to_a.map(&:year).should == [2008, 2009, 2010, 2011]
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'does not include christmas day 2009' do
|
42
|
+
interval.should_not include(Date.new(2009,12,24))
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'christmas day 2009 is less than max' do
|
46
|
+
Date.new(2009,12,24).should < interval.max
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'christmas day 2009 is greater than min' do
|
50
|
+
Date.new(2009,12,24).should > interval.min
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'covers christmas day 2009' do
|
54
|
+
interval.should cover(Date.new(2009,12,24))
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'covers 2011-12-31' do
|
58
|
+
interval.should cover(Date.new(2011,12,31))
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'the interval 2008-08-23/2011-07-01' do
|
64
|
+
let(:interval) { Date.edtf('2008-08-23/2011-07-01') }
|
65
|
+
|
66
|
+
it 'includes christmas day 2009' do
|
67
|
+
interval.should include(Date.new(2009,12,24))
|
68
|
+
end
|
6
69
|
|
7
|
-
it '
|
8
|
-
interval.should
|
70
|
+
it 'covers christmas day 2009' do
|
71
|
+
interval.should cover(Date.new(2009,12,24))
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'does not cover 2011-07-02' do
|
75
|
+
interval.should_not cover(Date.new(2011,07,02))
|
9
76
|
end
|
10
77
|
end
|
78
|
+
|
79
|
+
describe 'the interval 2008-08-23/open' do
|
80
|
+
let(:interval) { Date.edtf('2008-08-23/open') }
|
81
|
+
|
82
|
+
it { interval.should be_open }
|
83
|
+
it { interval.should be_open_end }
|
84
|
+
it { interval.should_not be_unknown }
|
85
|
+
it { interval.should_not be_unknown_start }
|
86
|
+
it { interval.should_not be_unknown_end }
|
87
|
+
|
88
|
+
it 'the min date is 2008-08-23' do
|
89
|
+
interval.min.should == Date.new(2008,8,23)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'the max date is nil' do
|
93
|
+
interval.max.should be nil
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'includes christmas day 2009' do
|
97
|
+
interval.should include(Date.new(2009,12,24))
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'covers christmas day 2009' do
|
101
|
+
interval.should cover(Date.new(2009,12,24))
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'covers 2023-07-02' do
|
105
|
+
interval.should cover(Date.new(2023,07,02))
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
describe 'comparisions' do
|
111
|
+
|
112
|
+
it '2007/2009 should be greater than 2001/2002' do
|
113
|
+
Date.edtf('2007/2009').should > Date.edtf('2001/2002')
|
114
|
+
end
|
115
|
+
|
116
|
+
it '2007/2009 should be less than 2011/2012' do
|
117
|
+
Date.edtf('2007/2009').should < Date.edtf('2011/2012')
|
118
|
+
end
|
119
|
+
|
120
|
+
it '2007/2009 should be less than 2008/2009' do
|
121
|
+
Date.edtf('2007/2009').should < Date.edtf('2008/2009')
|
122
|
+
end
|
123
|
+
|
124
|
+
it '2007/2009 should be greater than 2007/2008' do
|
125
|
+
Date.edtf('2007/2009').should > Date.edtf('2007/2008')
|
126
|
+
end
|
127
|
+
|
128
|
+
it '2007/2009 should be greater than 2006/2007' do
|
129
|
+
Date.edtf('2007/2009').should > Date.edtf('2006/2007')
|
130
|
+
end
|
131
|
+
|
132
|
+
it '2007/2009 should be equal to 2007/2009' do
|
133
|
+
Date.edtf('2007/2009').should == Date.edtf('2007/2009')
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
end
|
11
139
|
end
|
12
140
|
end
|
data/spec/edtf/parser_spec.rb
CHANGED
@@ -23,9 +23,7 @@ module EDTF
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'parses simple intervals like "2007/2008"' do
|
26
|
-
Parser.new.parse('2007/2008').should
|
27
|
-
Parser.new.parse('2007/2008').should include(Date.new(2008,1,2))
|
28
|
-
Parser.new.parse('2007/2008').should_not include(Date.new(2009,1,2))
|
26
|
+
Parser.new.parse('2007/2008').should be_a(Interval)
|
29
27
|
end
|
30
28
|
|
31
29
|
it 'parses uncertain dates' do
|
@@ -67,130 +65,139 @@ module EDTF
|
|
67
65
|
Parser.new.parse('1984-06-02?/2004-08-08~').to.should be_approximate
|
68
66
|
end
|
69
67
|
|
70
|
-
it '
|
68
|
+
it 'parses positive long years' do
|
71
69
|
Parser.new.parse('y170000002').year.should == 170000002
|
72
70
|
end
|
73
71
|
|
74
|
-
it '
|
72
|
+
it 'parses negative long years' do
|
75
73
|
Parser.new.parse('y-170000002').year.should == -170000002
|
76
74
|
end
|
77
75
|
|
78
|
-
it '
|
76
|
+
it 'parses season codes' do
|
79
77
|
Parser.new.parse('2003-23').should be_autumn
|
80
78
|
end
|
81
79
|
|
82
|
-
it '
|
80
|
+
it 'parses calendar names' do
|
83
81
|
Parser.new.parse('2001-02-03^xyz').calendar.should == 'xyz'
|
84
82
|
end
|
85
83
|
|
86
|
-
it '
|
84
|
+
it 'parses season qualifiers' do
|
87
85
|
d = Parser.new.parse('2003-23^european')
|
88
86
|
d.should be_autumn
|
89
87
|
d.should be_qualified
|
90
88
|
d.qualifier.should == 'european'
|
91
89
|
end
|
92
90
|
|
93
|
-
it '
|
91
|
+
it 'parses positive scientific long years' do
|
94
92
|
Parser.new.parse('y17e7').year.should == 170000000
|
95
93
|
end
|
96
94
|
|
97
|
-
it '
|
95
|
+
it 'parses negative scientific long years' do
|
98
96
|
Parser.new.parse('y-17e7').year.should == -170000000
|
99
97
|
end
|
100
98
|
|
101
99
|
it 'parses masked precision date strings (decades)' do
|
102
|
-
d = Parser.new.parse('198x')
|
100
|
+
d = Parser.new.parse!('198x')
|
103
101
|
d.should include(Date.new(1983,3,12))
|
104
102
|
d.should_not include(Date.new(1990,1,1))
|
105
103
|
end
|
106
104
|
|
107
105
|
it 'parses masked precision date strings (centuries)' do
|
108
|
-
d = Parser.new.parse('18xx')
|
106
|
+
d = Parser.new.parse!('18xx')
|
109
107
|
d.should include(Date.new(1848,1,14))
|
110
108
|
d.should_not include(Date.new(1799,12,31))
|
111
109
|
end
|
112
110
|
|
113
111
|
it 'parses multiple dates (years)' do
|
114
|
-
d = Parser.new.parse('{1667,1668, 1670..1672}')
|
112
|
+
d = Parser.new.parse!('{1667,1668, 1670..1672}')
|
115
113
|
d.map(&:year).should == [1667,1668,1670,1671,1672]
|
116
114
|
end
|
117
115
|
|
118
116
|
it 'parses multiple dates (mixed years and months)' do
|
119
|
-
d = Parser.new.parse('{1960, 1961-12}')
|
117
|
+
d = Parser.new.parse!('{1960, 1961-12}')
|
120
118
|
d.map { |x| [x.year,x.month] }.should == [[1960,1],[1961,12]]
|
121
119
|
end
|
122
120
|
|
123
121
|
it 'parses choice lists (One of the years 1667, 1668, 1670, 1671, 1672)' do
|
124
|
-
d = Parser.new.parse('[1667,1668, 1670..1672]')
|
122
|
+
d = Parser.new.parse!('[1667,1668, 1670..1672]')
|
125
123
|
d.map(&:year).should == [1667,1668,1670,1671,1672]
|
126
124
|
end
|
127
125
|
|
128
126
|
it 'parses choice lists (December 3, 1760 or some earlier date)' do
|
129
|
-
d = Parser.new.parse('[..1760-12-03]')
|
127
|
+
d = Parser.new.parse!('[..1760-12-03]')
|
130
128
|
d.map(&:to_s).should == ['1760-12-03']
|
131
129
|
end
|
132
130
|
|
133
131
|
it 'parses choice lists (December 1760 or some later month)' do
|
134
|
-
d = Parser.new.parse('[1760-12..]')
|
132
|
+
d = Parser.new.parse!('[1760-12..]')
|
135
133
|
d.map { |x| [x.year,x.month] }.should == [[1760,12]]
|
136
134
|
end
|
137
135
|
|
138
136
|
it 'parses choice lists (January or February of 1760 or December 1760 or some later month)' do
|
139
|
-
d = Parser.new.parse('[1760-01, 1760-02, 1760-12..]')
|
137
|
+
d = Parser.new.parse!('[1760-01, 1760-02, 1760-12..]')
|
140
138
|
d.length.should == 3
|
141
139
|
end
|
142
140
|
|
143
141
|
it 'parses intern unspecified "199u-01-01"' do
|
144
|
-
Parser.new.parse('199u-01-01').unspecified.to_s.should == 'sssu-ss-ss'
|
142
|
+
Parser.new.parse!('199u-01-01').unspecified.to_s.should == 'sssu-ss-ss'
|
145
143
|
end
|
146
144
|
|
147
145
|
it 'parses intern unspecified "19uu-01-01"' do
|
148
|
-
Parser.new.parse('19uu-01-01').unspecified.to_s.should == 'ssuu-ss-ss'
|
146
|
+
Parser.new.parse!('19uu-01-01').unspecified.to_s.should == 'ssuu-ss-ss'
|
149
147
|
end
|
150
148
|
|
151
149
|
it 'parses intern unspecified "199u-uu-01"' do
|
152
|
-
Parser.new.parse('199u-uu-01').unspecified.to_s.should == 'sssu-uu-ss'
|
150
|
+
Parser.new.parse!('199u-uu-01').unspecified.to_s.should == 'sssu-uu-ss'
|
153
151
|
end
|
154
152
|
|
155
153
|
it 'parses intern unspecified "19uu-uu-01"' do
|
156
|
-
Parser.new.parse('19uu-uu-01').unspecified.to_s.should == 'ssuu-uu-ss'
|
154
|
+
Parser.new.parse!('19uu-uu-01').unspecified.to_s.should == 'ssuu-uu-ss'
|
157
155
|
end
|
158
156
|
|
159
157
|
it 'parses intern unspecified "199u-uu-uu"' do
|
160
|
-
Parser.new.parse('199u-uu-uu').unspecified.to_s.should == 'sssu-uu-uu'
|
158
|
+
Parser.new.parse!('199u-uu-uu').unspecified.to_s.should == 'sssu-uu-uu'
|
161
159
|
end
|
162
160
|
|
163
161
|
it 'parses intern unspecified "19uu-uu-uu"' do
|
164
|
-
Parser.new.parse('19uu-uu-uu').unspecified.to_s.should == 'ssuu-uu-uu'
|
162
|
+
Parser.new.parse!('19uu-uu-uu').unspecified.to_s.should == 'ssuu-uu-uu'
|
165
163
|
end
|
166
164
|
|
167
165
|
it 'parses intern unspecified "199u-01-uu"' do
|
168
|
-
Parser.new.parse('199u-01-uu').unspecified.to_s.should == 'sssu-ss-uu'
|
166
|
+
Parser.new.parse!('199u-01-uu').unspecified.to_s.should == 'sssu-ss-uu'
|
169
167
|
end
|
170
168
|
|
171
169
|
it 'parses intern unspecified "19uu-01-uu"' do
|
172
|
-
Parser.new.parse('19uu-01-uu').unspecified.to_s.should == 'ssuu-ss-uu'
|
170
|
+
Parser.new.parse!('19uu-01-uu').unspecified.to_s.should == 'ssuu-ss-uu'
|
173
171
|
end
|
174
172
|
|
175
173
|
it 'parses intern unspecified "1999-uu-01"' do
|
176
|
-
Parser.new.parse('1999-uu-01').unspecified.to_s.should == 'ssss-uu-ss'
|
174
|
+
Parser.new.parse!('1999-uu-01').unspecified.to_s.should == 'ssss-uu-ss'
|
177
175
|
end
|
176
|
+
|
177
|
+
it 'parses intern unspecified "2004-06-uu"' do
|
178
|
+
Parser.new.parse!('2004-06-uu').unspecified.to_s.should == 'ssss-ss-uu'
|
179
|
+
end
|
180
|
+
|
178
181
|
|
182
|
+
it 'parses internal unspecified interval "2004-06-uu/2004-07-03"' do
|
183
|
+
Parser.new.parse!('2004-06-uu/2004-07-03').from.should == Date.new(2004,6,1)
|
184
|
+
end
|
185
|
+
|
179
186
|
it 'parses "2004?-06-11": uncertain year; month, day known' do
|
180
|
-
d = Parser.new.parse('2004?-06-11')
|
187
|
+
d = Parser.new.parse!('2004?-06-11')
|
181
188
|
d.uncertain?(:year).should be true
|
182
189
|
d.uncertain?([:month, :day]).should be false
|
183
190
|
end
|
184
191
|
|
185
192
|
it 'parses "2004-06~-11": year and month are approximate; day known' do
|
186
|
-
d = Parser.new.parse('2004-06~-11')
|
193
|
+
d = Parser.new.parse!('2004-06~-11')
|
187
194
|
d.approximate?(:year).should be true
|
188
195
|
d.approximate?(:month).should be true
|
189
196
|
d.approximate?(:day).should be false
|
190
197
|
end
|
191
198
|
|
192
199
|
it 'parses "2004-(06)?-11": uncertain month, year and day known' do
|
193
|
-
d = Parser.new.parse('2004-(06)?-11')
|
200
|
+
d = Parser.new.parse!('2004-(06)?-11')
|
194
201
|
|
195
202
|
d.uncertain?(:year).should be false
|
196
203
|
d.approximate?(:year).should be false
|
@@ -203,15 +210,15 @@ module EDTF
|
|
203
210
|
end
|
204
211
|
|
205
212
|
it 'parses "2004-06-(11)~": day is approximate; year, month known' do
|
206
|
-
d = Parser.new.parse('2004-06-(11)~')
|
213
|
+
d = Parser.new.parse!('2004-06-(11)~')
|
207
214
|
d.approximate?(:year).should be false
|
208
215
|
d.approximate?(:month).should be false
|
209
216
|
d.approximate?(:day).should be true
|
210
217
|
end
|
211
218
|
|
212
219
|
it 'parses "2004-(06)?~": year known, month within year is approximate and uncertain' do
|
213
|
-
d = Parser.new.parse('2004-(06)?~')
|
214
|
-
|
220
|
+
d = Parser.new.parse!('2004-(06)?~')
|
221
|
+
|
215
222
|
d.approximate?(:year).should be false
|
216
223
|
d.uncertain?(:year).should be false
|
217
224
|
|
@@ -223,7 +230,7 @@ module EDTF
|
|
223
230
|
end
|
224
231
|
|
225
232
|
it 'parses "2004-(06-11)?": year known, month and day uncertain' do
|
226
|
-
d = Parser.new.parse('2004-(06-11)?')
|
233
|
+
d = Parser.new.parse!('2004-(06-11)?')
|
227
234
|
|
228
235
|
d.approximate?(:year).should be false
|
229
236
|
d.uncertain?(:year).should be false
|
@@ -249,7 +256,7 @@ module EDTF
|
|
249
256
|
end
|
250
257
|
|
251
258
|
it 'parses "(2004-(06)~)?": year uncertain and month is both uncertain and approximate' do
|
252
|
-
d = Parser.new.parse('(2004-(06)~)?')
|
259
|
+
d = Parser.new.parse!('(2004-(06)~)?')
|
253
260
|
|
254
261
|
d.approximate?(:year).should be false
|
255
262
|
d.uncertain?(:year).should be true
|
@@ -261,6 +268,20 @@ module EDTF
|
|
261
268
|
d.uncertain?(:day).should be false
|
262
269
|
end
|
263
270
|
|
271
|
+
it 'parses "2004~-(06)?-01~": year and day approximate, month uncertain' do
|
272
|
+
d = Parser.new.parse!("2004~-(06)?-01~")
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'parses "2004~-(06-(01)~)?": year and day approximate, month and day uncertain' do
|
276
|
+
d = Parser.new.parse!("2004~-(06-(01)~)?")
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'parses "2004~-(06)?-01?~": year and day approximate, month and day uncertain' do
|
280
|
+
d = Parser.new.parse!("2004~-(06)?-01?~")
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
|
264
285
|
end
|
265
286
|
end
|
266
287
|
end
|
@@ -13,14 +13,15 @@ module EDTF
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should not be uncertain if all parts are certain' do
|
16
|
-
Uncertainty.new(false, false, false
|
16
|
+
Uncertainty.new(false, false, false).should be_certain
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should be uncertain if all parts are uncertain' do
|
20
|
-
Uncertainty.new(true, true, true
|
20
|
+
Uncertainty.new(true, true, true).should be_uncertain
|
21
21
|
end
|
22
22
|
|
23
|
-
[:year, :month, :day, :hour, :minute, :second].each do |part|
|
23
|
+
# [:year, :month, :day, :hour, :minute, :second].each do |part|
|
24
|
+
[:year, :month, :day].each do |part|
|
24
25
|
it "#{ part } should not be uncertain by default" do
|
25
26
|
uncertainty.uncertain?(part).should be false
|
26
27
|
end
|
@@ -30,12 +31,53 @@ module EDTF
|
|
30
31
|
uncertainty.uncertain?(part).should be true
|
31
32
|
end
|
32
33
|
|
33
|
-
([:year, :month, :day, :hour, :minute, :second] - [part]).each do |other|
|
34
|
+
# ([:year, :month, :day, :hour, :minute, :second] - [part]).each do |other|
|
35
|
+
([:year, :month, :day] - [part]).each do |other|
|
34
36
|
it "#{other} should not be uncertain if #{part} is uncertain" do
|
35
37
|
uncertainty.send("#{part}=", true)
|
36
38
|
uncertainty.uncertain?(other).should be false
|
37
39
|
end
|
38
40
|
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#hash' do
|
45
|
+
|
46
|
+
describe 'with the default hash base (1)' do
|
47
|
+
|
48
|
+
it 'returns 0 by default' do
|
49
|
+
Uncertainty.new.hash.should == 0
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns 1 for uncertain year' do
|
53
|
+
Uncertainty.new.hash.should == 0
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns 2 for uncertain month' do
|
57
|
+
Uncertainty.new.hash.should == 0
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns 4 for uncertain day' do
|
61
|
+
Uncertainty.new.hash.should == 0
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns 3 for uncertain year, month' do
|
65
|
+
Uncertainty.new(true, true).hash.should == 3
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns 7 for uncertain year, month, day' do
|
69
|
+
Uncertainty.new(true, true, true).hash.should == 7
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns 5 for uncertain year, day' do
|
73
|
+
Uncertainty.new(true, nil, true).hash.should == 5
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns 6 for uncertain month, day' do
|
77
|
+
Uncertainty.new(nil, true, true).hash.should == 6
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
39
81
|
|
40
82
|
end
|
41
83
|
|
@@ -108,6 +150,127 @@ module EDTF
|
|
108
150
|
end
|
109
151
|
|
110
152
|
end
|
153
|
+
|
154
|
+
describe '#mask' do
|
155
|
+
|
156
|
+
context 'when passed an empty array' do
|
157
|
+
it 'should return an empty array' do
|
158
|
+
u.mask([]).should == []
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'when passed an array with a year string' do
|
163
|
+
let(:date) { ['1994'] }
|
164
|
+
|
165
|
+
it 'should return the array with the year by default' do
|
166
|
+
u.mask(date).should == ['1994']
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'when the year is unspecified' do
|
170
|
+
before(:each) { u.year[3] = true }
|
171
|
+
|
172
|
+
it 'should return the array with the year and the fourth digit masked' do
|
173
|
+
u.mask(date).should == ['199u']
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'when the decade is unspecified' do
|
179
|
+
before(:each) { u.year[2,2] = [true,true] }
|
180
|
+
|
181
|
+
it 'should return the array with the year and the third and fourth digit masked' do
|
182
|
+
u.mask(date).should == ['19uu']
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when passed an array with a year-month string' do
|
190
|
+
let(:date) { ['1994', '01'] }
|
191
|
+
|
192
|
+
it 'should return the array with the year by default' do
|
193
|
+
u.mask(date).should == ['1994', '01']
|
194
|
+
end
|
195
|
+
|
196
|
+
context 'when the year is unspecified' do
|
197
|
+
before(:each) { u.year[3] = true }
|
198
|
+
|
199
|
+
it 'should return the array with the year and the fourth digit masked' do
|
200
|
+
u.mask(date).should == ['199u', '01']
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'when the month is unspecified' do
|
204
|
+
before(:each) { u.unspecified! :month }
|
205
|
+
|
206
|
+
it 'should return the array with the month masked' do
|
207
|
+
u.mask(date).should == ['199u', 'uu']
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'when the decade is unspecified' do
|
213
|
+
before(:each) { u.year[2,2] = [true,true] }
|
214
|
+
|
215
|
+
it 'should return the array with the year and the third and fourth digit masked' do
|
216
|
+
u.mask(date).should == ['19uu', '01']
|
217
|
+
end
|
218
|
+
|
219
|
+
context 'when the month is unspecified' do
|
220
|
+
before(:each) { u.unspecified! :month }
|
221
|
+
|
222
|
+
it 'should return the array with the month masked' do
|
223
|
+
u.mask(date).should == ['19uu', 'uu']
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context 'when the month is unspecified' do
|
229
|
+
before(:each) { u.unspecified! :month }
|
230
|
+
|
231
|
+
it 'should return the array with the month masked' do
|
232
|
+
u.mask(date).should == ['1994', 'uu']
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
context 'when passed an array with a year-month-day string' do
|
239
|
+
let(:date) { ['1994', '01', '27'] }
|
240
|
+
|
241
|
+
it 'should return the array with the date by default' do
|
242
|
+
u.mask(date).should == ['1994', '01', '27']
|
243
|
+
end
|
244
|
+
|
245
|
+
context 'when the year is unspecified' do
|
246
|
+
before(:each) { u.year[3] = true }
|
247
|
+
|
248
|
+
it 'should return the array with the year and the fourth digit masked' do
|
249
|
+
u.mask(date).should == ['199u', '01', '27']
|
250
|
+
end
|
251
|
+
|
252
|
+
context 'when the month is unspecified' do
|
253
|
+
before(:each) { u.unspecified! :month }
|
254
|
+
|
255
|
+
it 'should return the array with the month masked' do
|
256
|
+
u.mask(date).should == ['199u', 'uu', '27']
|
257
|
+
end
|
258
|
+
|
259
|
+
context 'when the day is unspecified' do
|
260
|
+
before(:each) { u.unspecified! :day }
|
261
|
+
|
262
|
+
it 'should return the array with the month masked' do
|
263
|
+
u.mask(date).should == ['199u', 'uu', 'uu']
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
|
273
|
+
end
|
111
274
|
|
112
275
|
end
|
113
276
|
|