edtf 3.2.0 → 4.0.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/LICENSE +1 -1
- data/README.md +145 -118
- data/lib/edtf/date.rb +39 -2
- data/lib/edtf/epoch.rb +3 -1
- data/lib/edtf/interval.rb +56 -28
- data/lib/edtf/parser.rb +797 -686
- data/lib/edtf/parser.y +67 -35
- data/lib/edtf/season.rb +10 -2
- data/lib/edtf/set.rb +15 -1
- data/lib/edtf/uncertainty.rb +7 -8
- data/lib/edtf/version.rb +1 -1
- metadata +28 -64
- data/.autotest +0 -8
- data/.github/workflows/ci.yml +0 -41
- data/.gitignore +0 -8
- data/.rspec +0 -3
- data/.simplecov +0 -19
- data/Gemfile +0 -22
- data/Rakefile +0 -68
- data/cucumber.yml +0 -1
- data/edtf.gemspec +0 -29
- data/features/parser/date_times.feature +0 -41
- data/features/parser/dates.feature +0 -89
- data/features/parser/intervals.feature +0 -18
- data/features/parser/precision.feature +0 -14
- data/features/parser/uncertain_or_approximate.feature +0 -129
- data/features/parser/unspecified.feature +0 -34
- data/features/print/level_0_edtf.feature +0 -79
- data/features/print/level_1_edtf.feature +0 -137
- data/features/print/level_2_edtf.feature +0 -39
- data/features/print/uncertain_or_approximate.feature +0 -131
- data/features/step_definitions/edtf_steps.rb +0 -148
- data/features/support/env.rb +0 -13
- data/spec/edtf/date_spec.rb +0 -245
- data/spec/edtf/epoch_spec.rb +0 -88
- data/spec/edtf/interval_spec.rb +0 -161
- data/spec/edtf/parser_spec.rb +0 -427
- data/spec/edtf/season_spec.rb +0 -111
- data/spec/edtf/set_spec.rb +0 -82
- data/spec/edtf/uncertainty_spec.rb +0 -296
- data/spec/spec_helper.rb +0 -15
data/spec/edtf/set_spec.rb
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
module EDTF
|
|
2
|
-
describe 'Sets' do
|
|
3
|
-
|
|
4
|
-
describe 'constructor' do
|
|
5
|
-
|
|
6
|
-
it 'creates a new empty set by default' do
|
|
7
|
-
expect(Set.new).to be_empty
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe '#edtf' do
|
|
13
|
-
|
|
14
|
-
it 'returns {} by default' do
|
|
15
|
-
expect(Set.new.edtf).to eq('{}')
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'returns [] for empty choice lists' do
|
|
19
|
-
expect(Set.new.choice!.edtf).to eq('[]')
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'returns {1984} if the set contains the year 1984' do
|
|
23
|
-
expect(Set.new(Date.edtf('1984')).edtf).to eq('{1984}')
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it 'returns {1984, 1985-10} for the set containing these dates' do
|
|
27
|
-
expect(Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).edtf).to eq('{1984,1984-10}')
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it 'returns {..1984, 1985-10} for the set containing these dates and earlier == true' do
|
|
31
|
-
expect(Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).earlier!.edtf).to eq('{..1984,1984-10}')
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'returns {1984, 1985-10..} for the set containing these dates and later == true' do
|
|
35
|
-
expect(Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).later!.edtf).to eq('{1984,1984-10..}')
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'returns [1667, 1668, 1670..1672] for the years 1667, 1668 and the interval 1670..1672' do
|
|
39
|
-
s = Set.new.choice!
|
|
40
|
-
s << Date.edtf('1667') << Date.edtf('1668')
|
|
41
|
-
s << (Date.edtf('1670') .. Date.edtf('1672'))
|
|
42
|
-
expect(s.edtf).to eq('[1667,1668,1670..1672]')
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe 'the set [1667, 1668, 1670..1672]' do
|
|
48
|
-
let(:set) { Set.new(Date.edtf('1667'), Date.edtf('1668'), Date.edtf('1670')..Date.edtf('1672')).choice! }
|
|
49
|
-
|
|
50
|
-
it 'includes the year 1671' do
|
|
51
|
-
expect(set).to include(Date.new(1671).year_precision!)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it 'does not include the date 1671-01-01' do
|
|
55
|
-
expect(set.include?(Date.new(1671))).to be false
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'does not include the year 1669' do
|
|
59
|
-
expect(set.include?(Date.new(1669).year_precision!)).to be false
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it 'has a length of 3' do
|
|
63
|
-
expect(set.size).to eq(3)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it 'maps to the year array [1667,1668,1670,1671,1672]' do
|
|
67
|
-
expect(set.map(&:year)).to eq([1667, 1668, 1670, 1671, 1672])
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe 'the set [1984,1985-10-01..]' do
|
|
72
|
-
let(:s1) { Set.new(Date.edtf('1984'), Date.edtf('1985-10-01')).later! }
|
|
73
|
-
let(:s2) { Date.edtf('[1984,1985-10-01..]') }
|
|
74
|
-
|
|
75
|
-
it 'has varying precision' do
|
|
76
|
-
expect(s1.map(&:precision)).to eq([:year, :day])
|
|
77
|
-
expect(s2.map(&:precision)).to eq([:year, :day])
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
end
|
|
82
|
-
end
|
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
module EDTF
|
|
2
|
-
|
|
3
|
-
describe Uncertainty do
|
|
4
|
-
|
|
5
|
-
let(:uncertainty) { Uncertainty.new }
|
|
6
|
-
|
|
7
|
-
describe '#uncertain?' do
|
|
8
|
-
|
|
9
|
-
it { is_expected.to be_certain }
|
|
10
|
-
|
|
11
|
-
it 'should be uncertain if at least one part is uncertain' do
|
|
12
|
-
expect(Uncertainty.new(false, false, true)).to be_uncertain
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'should not be uncertain if all parts are certain' do
|
|
16
|
-
expect(Uncertainty.new(false, false, false)).to be_certain
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it 'should be uncertain if all parts are uncertain' do
|
|
20
|
-
expect(Uncertainty.new(true, true, true)).to be_uncertain
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# [:year, :month, :day, :hour, :minute, :second].each do |part|
|
|
24
|
-
[:year, :month, :day].each do |part|
|
|
25
|
-
it "#{ part } should not be uncertain by default" do
|
|
26
|
-
expect(uncertainty.uncertain?(part)).to be false
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "#{ part } should be uncertain if set to uncertain" do
|
|
30
|
-
uncertainty.send("#{part}=", true)
|
|
31
|
-
expect(uncertainty.uncertain?(part)).to be true
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# ([:year, :month, :day, :hour, :minute, :second] - [part]).each do |other|
|
|
35
|
-
([:year, :month, :day] - [part]).each do |other|
|
|
36
|
-
it "#{other} should not be uncertain if #{part} is uncertain" do
|
|
37
|
-
uncertainty.send("#{part}=", true)
|
|
38
|
-
expect(uncertainty.uncertain?(other)).to be false
|
|
39
|
-
end
|
|
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
|
-
expect(Uncertainty.new.hash).to eq(0)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it 'returns 1 for uncertain year' do
|
|
53
|
-
expect(Uncertainty.new.hash).to eq(0)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it 'returns 2 for uncertain month' do
|
|
57
|
-
expect(Uncertainty.new.hash).to eq(0)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it 'returns 4 for uncertain day' do
|
|
61
|
-
expect(Uncertainty.new.hash).to eq(0)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'returns 3 for uncertain year, month' do
|
|
65
|
-
expect(Uncertainty.new(true, true).hash).to eq(3)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it 'returns 7 for uncertain year, month, day' do
|
|
69
|
-
expect(Uncertainty.new(true, true, true).hash).to eq(7)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it 'returns 5 for uncertain year, day' do
|
|
73
|
-
expect(Uncertainty.new(true, nil, true).hash).to eq(5)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it 'returns 6 for uncertain month, day' do
|
|
77
|
-
expect(Uncertainty.new(nil, true, true).hash).to eq(6)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
describe '#uncertain!' do
|
|
87
|
-
it 'should make all parts certain when no part given' do
|
|
88
|
-
expect { uncertainty.uncertain! }.to change { uncertainty.certain? }
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
describe Unspecified do
|
|
95
|
-
let(:u) { Unspecified.new }
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
describe '#unspecified?' do
|
|
99
|
-
it 'should return false by default' do
|
|
100
|
-
expect(u).not_to be_unspecified
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it 'should return true if the day is unspecified' do
|
|
104
|
-
expect(u.unspecified!(:day)).to be_unspecified
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
it 'should return true if the month is unspecified' do
|
|
108
|
-
expect(u.unspecified!(:month)).to be_unspecified
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it 'should return true if the year is unspecified' do
|
|
112
|
-
expect(u.unspecified!(:year)).to be_unspecified
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
describe '#year' do
|
|
117
|
-
it 'returns the year values' do
|
|
118
|
-
expect(u.year).to eq([nil,nil,nil,nil])
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
it 'allows you to set individual offsets' do
|
|
122
|
-
u.year[1] = true
|
|
123
|
-
expect(u.to_s).to eq('sXss-ss-ss')
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
describe '#to_s' do
|
|
128
|
-
it 'should be return "ssss-ss-ss" by default' do
|
|
129
|
-
expect(u.to_s).to eq('ssss-ss-ss')
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it 'should return "ssss-ss-uu" if the day is unspecified' do
|
|
133
|
-
expect(u.unspecified!(:day).to_s).to eq('ssss-ss-XX')
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it 'should return "ssss-uu-ss" if the month is unspecified' do
|
|
137
|
-
expect(u.unspecified!(:month).to_s).to eq('ssss-XX-ss')
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it 'should return "ssss-uu-uu" if month and day are unspecified' do
|
|
141
|
-
expect(u.unspecified!([:day, :month]).to_s).to eq('ssss-XX-XX')
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
it 'should return "uuuu-ss-ss" if the year is unspecified' do
|
|
145
|
-
expect(u.unspecified!(:year).to_s).to eq('XXXX-ss-ss')
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
it 'should return "uuuu-uu-uu" if the date is unspecified' do
|
|
149
|
-
expect(u.unspecified!.to_s).to eq('XXXX-XX-XX')
|
|
150
|
-
end
|
|
151
|
-
|
|
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
|
-
expect(u.mask([])).to eq([])
|
|
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
|
-
expect(u.mask(date)).to eq(['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
|
-
expect(u.mask(date)).to eq(['199X'])
|
|
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
|
-
expect(u.mask(date)).to eq(['19XX'])
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
context 'when passed an array with a negative year string' do
|
|
190
|
-
let(:date) { ['-1994'] }
|
|
191
|
-
|
|
192
|
-
it 'should return the array with the year by default' do
|
|
193
|
-
expect(u.mask(date)).to eq(['-1994'])
|
|
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
|
-
expect(u.mask(date)).to eq(['-199X'])
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
context 'when the decade is unspecified' do
|
|
205
|
-
before(:each) { u.year[2,2] = [true,true] }
|
|
206
|
-
|
|
207
|
-
it 'should return the array with the year and the third and fourth digit masked' do
|
|
208
|
-
expect(u.mask(date)).to eq(['-19XX'])
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
context 'when passed an array with a year-month string' do
|
|
215
|
-
let(:date) { ['1994', '01'] }
|
|
216
|
-
|
|
217
|
-
it 'should return the array with the year by default' do
|
|
218
|
-
expect(u.mask(date)).to eq(['1994', '01'])
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
context 'when the year is unspecified' do
|
|
222
|
-
before(:each) { u.year[3] = true }
|
|
223
|
-
|
|
224
|
-
it 'should return the array with the year and the fourth digit masked' do
|
|
225
|
-
expect(u.mask(date)).to eq(['199X', '01'])
|
|
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
|
-
expect(u.mask(date)).to eq(['199X', 'XX'])
|
|
233
|
-
end
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
context 'when the decade is unspecified' do
|
|
238
|
-
before(:each) { u.year[2,2] = [true,true] }
|
|
239
|
-
|
|
240
|
-
it 'should return the array with the year and the third and fourth digit masked' do
|
|
241
|
-
expect(u.mask(date)).to eq(['19XX', '01'])
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
context 'when the month is unspecified' do
|
|
245
|
-
before(:each) { u.unspecified! :month }
|
|
246
|
-
|
|
247
|
-
it 'should return the array with the month masked' do
|
|
248
|
-
expect(u.mask(date)).to eq(['19XX', 'XX'])
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
context 'when the month is unspecified' do
|
|
254
|
-
before(:each) { u.unspecified! :month }
|
|
255
|
-
|
|
256
|
-
it 'should return the array with the month masked' do
|
|
257
|
-
expect(u.mask(date)).to eq(['1994', 'XX'])
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
context 'when passed an array with a year-month-day string' do
|
|
264
|
-
let(:date) { ['1994', '01', '27'] }
|
|
265
|
-
|
|
266
|
-
it 'should return the array with the date by default' do
|
|
267
|
-
expect(u.mask(date)).to eq(['1994', '01', '27'])
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
context 'when the year is unspecified' do
|
|
271
|
-
before(:each) { u.year[3] = true }
|
|
272
|
-
|
|
273
|
-
it 'should return the array with the year and the fourth digit masked' do
|
|
274
|
-
expect(u.mask(date)).to eq(['199X', '01', '27'])
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
context 'when the month is unspecified' do
|
|
278
|
-
before(:each) { u.unspecified! :month }
|
|
279
|
-
|
|
280
|
-
it 'should return the array with the month masked' do
|
|
281
|
-
expect(u.mask(date)).to eq(['199X', 'XX', '27'])
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
context 'when the day is unspecified' do
|
|
285
|
-
before(:each) { u.unspecified! :day }
|
|
286
|
-
|
|
287
|
-
it 'should return the array with the month masked' do
|
|
288
|
-
expect(u.mask(date)).to eq(['199X', 'XX', 'XX'])
|
|
289
|
-
end
|
|
290
|
-
end
|
|
291
|
-
end
|
|
292
|
-
end
|
|
293
|
-
end
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
end
|
data/spec/spec_helper.rb
DELETED