flexyear 2.2.2 → 2.3.0

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: 2ba90e3142ece7c435fd2ee4acc7d7ca19ef77f0
4
- data.tar.gz: 7880df13f9e0be791c7ec842ae79094d7bf24990
3
+ metadata.gz: 9e9174d74ff69cacee7ce260b97f5d078df55504
4
+ data.tar.gz: 4b24e5c479bb602a2622f5460ec391cd0ef17390
5
5
  SHA512:
6
- metadata.gz: d993fd9336e03ae8563077141830884fc2efdeeb3f1eb9ed4aee6f92f4282fa1cfcc40395848ddd5849669d16dae4408cf56330cf196e7bea97cdb2cca5f13aa
7
- data.tar.gz: c9fc713af6a53ab7551a47a2c949a8a30a8e01fd567f98dfe98d08da226fc7c27dcdb482bfd2cc42e34ca070eeb731e7503844839a85f662208ded0061297722
6
+ metadata.gz: 0d18648d7172c4accb880dc63047fedfc590e7c5d76ca74f42a60279aad65e8e790a238612bccd69d8dadd2f15e7eabc0b04ec5ef100a8a8a88c71231e8e7ea1
7
+ data.tar.gz: 534ea4c77aaec2aa1ef32661c92472ced07f5817a44773b1da7c7867be5971e61037a777aa5319b8f1797f6e64dd499193a21687a200b6a3f53f1f071980806e
data/README.md CHANGED
@@ -7,15 +7,23 @@ Examples:
7
7
  ```ruby
8
8
  FlexYear.new("1980s").year_low == 1980
9
9
  FlexYear.new("1980s").year_high == 1989
10
+ FlexYear.new("1980s").decade == 1980s
10
11
 
11
12
  FlexYear.new("mid-80s").year_low == 1983
12
13
  FlexYear.new("mid-80s").year_high == 1986
14
+ FlexYear.new("mid-80s").decade == 1980s
13
15
 
14
16
  FlexYear.new(1983).year_low == 1983
15
17
  FlexYear.new(1983).year_high == 1983
18
+ FlexYear.new(1983).decade == 1980s
19
+
20
+ FlexYear.new(198*).year_low == 1980
21
+ FlexYear.new(198*).year_high == 1989
22
+ FlexYear.new(198*).decade == 1980s
16
23
 
17
24
  FlexYear.new(["1980s", "1988 - 2000", 2001]).year_low == 1980
18
25
  FlexYear.new(["1980s", "1988 - 2000", 2001]).year_high == 2001
26
+ FlexYear.new(["1980s", "1988 - 2000", nil, 2001]).decades == [1980s, nil, nil, 2000s]
19
27
  ```
20
28
 
21
29
  It's pretty flexible in the kinds of things it takes. For more examples, see the spec.
data/lib/flexyear.rb CHANGED
@@ -23,7 +23,7 @@ require 'date'
23
23
  class FlexYear
24
24
  class InvalidYearError < ArgumentError; end
25
25
 
26
- attr_reader :year_low, :year_high
26
+ attr_reader :year_low, :year_high, :decade, :decades
27
27
 
28
28
  def initialize(year_input)
29
29
  @year_input = year_input
@@ -44,6 +44,21 @@ class FlexYear
44
44
  year_low % 10 == 0 && year_high % 10 == 9
45
45
  end
46
46
 
47
+ def parse_decade(yr_low, yr_high)
48
+ return if @year_input.is_a?(Array)
49
+ return unless yr_low && yr_high
50
+
51
+ same_decade = yr_low.to_s[0,3] == yr_high.to_s[0, 3]
52
+ @decade = "#{yr_low.to_s[0,3]}0s" if same_decade
53
+ end
54
+
55
+ def parse_decades(years)
56
+ return unless @year_input.is_a?(Array)
57
+
58
+ parsed_decades = years.flat_map { |y| self.class.new(y).decade }
59
+ @decades = parsed_decades
60
+ end
61
+
47
62
  private
48
63
 
49
64
  def parse_year_list(years)
@@ -56,10 +71,13 @@ class FlexYear
56
71
 
57
72
  @year_low = flat_years.min
58
73
  @year_high = flat_years.max
74
+
75
+ parse_decades(years)
59
76
  end
60
77
 
61
78
  def parse_year_string(year_string)
62
79
  parse_year(year_string.to_s.strip)
80
+ parse_decade(@year_low, @year_high)
63
81
  end
64
82
 
65
83
  def centuryize(year, base_year=nil)
@@ -1,3 +1,3 @@
1
1
  class FlexYear
2
- VERSION = "2.2.2"
2
+ VERSION = "2.3.0"
3
3
  end
@@ -13,6 +13,8 @@ describe FlexYear do
13
13
  its(:year_low) { should be_nil }
14
14
  its(:year_high) { should be_nil }
15
15
  its(:decade?) { should eq(false) }
16
+ its(:decade) { should be_nil }
17
+ its(:decades) { should be_nil }
16
18
  end
17
19
 
18
20
  context "given nil" do
@@ -20,6 +22,8 @@ describe FlexYear do
20
22
  its(:year_low) { should be_nil }
21
23
  its(:year_high) { should be_nil }
22
24
  its(:decade?) { should eq(false) }
25
+ its(:decade) { should be_nil }
26
+ its(:decades) { should be_nil }
23
27
  end
24
28
 
25
29
  context "text" do
@@ -27,6 +31,8 @@ describe FlexYear do
27
31
  its(:year_low) { should be_nil }
28
32
  its(:year_high) { should be_nil }
29
33
  its(:decade?) { should eq(false) }
34
+ its(:decade) { should be_nil }
35
+ its(:decades) { should be_nil }
30
36
  end
31
37
 
32
38
  context "given 1979 as number" do
@@ -34,6 +40,8 @@ describe FlexYear do
34
40
  its(:year_low) { should eq(1979) }
35
41
  its(:year_high) { should eq(1979) }
36
42
  its(:decade?) { should eq(false) }
43
+ its(:decade) { should eq("1970s") }
44
+ its(:decades) { should be_nil }
37
45
  end
38
46
 
39
47
  context "given 1979" do
@@ -41,6 +49,8 @@ describe FlexYear do
41
49
  its(:year_low) { should eq(1979) }
42
50
  its(:year_high) { should eq(1979) }
43
51
  its(:decade?) { should eq(false) }
52
+ its(:decade) { should eq("1970s") }
53
+ its(:decades) { should be_nil }
44
54
  end
45
55
 
46
56
  context "given 1979 (with a space)" do
@@ -48,6 +58,8 @@ describe FlexYear do
48
58
  its(:year_low) { should eq(1979) }
49
59
  its(:year_high) { should eq(1979) }
50
60
  its(:decade?) { should eq(false) }
61
+ its(:decade) { should eq("1970s") }
62
+ its(:decades) { should be_nil }
51
63
  end
52
64
 
53
65
  context 'given 197*' do
@@ -55,6 +67,8 @@ describe FlexYear do
55
67
  its(:year_low) { should eq(1970) }
56
68
  its(:year_high) { should eq(1979) }
57
69
  its(:decade?) { should eq(true) }
70
+ its(:decade) { should eq("1970s") }
71
+ its(:decades) { should be_nil }
58
72
  end
59
73
 
60
74
  context "given 1970s" do
@@ -62,6 +76,8 @@ describe FlexYear do
62
76
  its(:year_low) { should eq(1970) }
63
77
  its(:year_high) { should eq(1979) }
64
78
  its(:decade?) { should eq(true) }
79
+ its(:decade) { should eq("1970s") }
80
+ its(:decades) { should be_nil }
65
81
  end
66
82
 
67
83
  context "given 70s" do
@@ -69,6 +85,8 @@ describe FlexYear do
69
85
  its(:year_low) { should eq(1970) }
70
86
  its(:year_high) { should eq(1979) }
71
87
  its(:decade?) { should eq(true) }
88
+ its(:decade) { should eq("1970s") }
89
+ its(:decades) { should be_nil }
72
90
  end
73
91
 
74
92
  context "given something with negative and dots" do
@@ -76,6 +94,8 @@ describe FlexYear do
76
94
  its(:year_low) { should eq(2005) }
77
95
  its(:year_high) { should eq(2007) }
78
96
  its(:decade?) { should eq(false) }
97
+ its(:decade) { should eq("2000s") }
98
+ its(:decades) { should be_nil }
79
99
  end
80
100
 
81
101
  context 'given before 1973' do
@@ -83,6 +103,8 @@ describe FlexYear do
83
103
  its(:year_low) { should be_nil }
84
104
  its(:year_high) { should eq(1973) }
85
105
  its(:decade?) { should eq(false) }
106
+ its(:decade) { should be_nil }
107
+ its(:decades) { should be_nil }
86
108
  end
87
109
 
88
110
  context 'given after 1973' do
@@ -90,6 +112,8 @@ describe FlexYear do
90
112
  its(:year_low) { should eq(1973) }
91
113
  its(:year_high) { should be_nil }
92
114
  its(:decade?) { should eq(false) }
115
+ its(:decade) { should be_nil }
116
+ its(:decades) { should be_nil }
93
117
  end
94
118
 
95
119
  ["mid 1970s", "mid 70s", "mid-70s", "mid-70's"].each do |year|
@@ -97,6 +121,8 @@ describe FlexYear do
97
121
  subject { flexyear_class.new(year) }
98
122
  its(:year_low) { should eq(1973) }
99
123
  its(:year_high) { should eq(1976) }
124
+ its(:decade) { should eq("1970s") }
125
+ its(:decades) { should be_nil }
100
126
  its(:to_s) { should eq(year) }
101
127
  its(:decade?) { should eq(false) }
102
128
  end
@@ -108,6 +134,8 @@ describe FlexYear do
108
134
  its(:year_low) { should eq(1970) }
109
135
  its(:year_high) { should eq(1973) }
110
136
  its(:decade?) { should eq(false) }
137
+ its(:decade) { should eq("1970s") }
138
+ its(:decades) { should be_nil }
111
139
  end
112
140
  end
113
141
 
@@ -117,6 +145,8 @@ describe FlexYear do
117
145
  its(:year_low) { should eq(1976) }
118
146
  its(:year_high) { should eq(1979) }
119
147
  its(:decade?) { should eq(false) }
148
+ its(:decade) { should eq("1970s") }
149
+ its(:decades) { should be_nil }
120
150
  end
121
151
  end
122
152
 
@@ -126,6 +156,8 @@ describe FlexYear do
126
156
  its(:year_low) { should eq(1973) }
127
157
  its(:year_high) { should eq(1975) }
128
158
  its(:decade?) { should eq(false) }
159
+ its(:decade) { should eq("1970s") }
160
+ its(:decades) { should be_nil }
129
161
  end
130
162
  end
131
163
 
@@ -133,7 +165,18 @@ describe FlexYear do
133
165
  subject { flexyear_class.new('1975-1973') }
134
166
  its(:year_low) { should eq(1973) }
135
167
  its(:year_high) { should eq(1975) }
136
- its(:decade?) { should eq(false) }
168
+ its(:decade?) { should eq(false) }
169
+ its(:decade) { should eq("1970s") }
170
+ its(:decades) { should be_nil }
171
+ end
172
+
173
+ context "given a range in difference decades" do
174
+ subject { flexyear_class.new('1975-1983') }
175
+ its(:year_low) { should eq(1975) }
176
+ its(:year_high) { should eq(1983) }
177
+ its(:decade?) { should eq(false) }
178
+ its(:decade) { should be_nil}
179
+ its(:decades) { should be_nil }
137
180
  end
138
181
 
139
182
  context "given a range" do
@@ -142,6 +185,8 @@ describe FlexYear do
142
185
  its(:year_low) { should eq(2003) }
143
186
  its(:year_high) { should eq(2004) }
144
187
  its(:decade?) { should eq(false) }
188
+ its(:decade) { should eq("2000s") }
189
+ its(:decades) { should be_nil }
145
190
  end
146
191
  end
147
192
 
@@ -151,6 +196,8 @@ describe FlexYear do
151
196
  its(:year_low) { should eq(1972) }
152
197
  its(:year_high) { should eq(1974) }
153
198
  its(:decade?) { should eq(false) }
199
+ its(:decade) { should eq("1970s") }
200
+ its(:decades) { should be_nil }
154
201
  end
155
202
 
156
203
  context 'at the beginning of the string' do
@@ -158,6 +205,8 @@ describe FlexYear do
158
205
  its(:year_low) { should eq(1972) }
159
206
  its(:year_high) { should eq(1974) }
160
207
  its(:decade?) { should eq(false) }
208
+ its(:decade) { should eq("1970s") }
209
+ its(:decades) { should be_nil }
161
210
  end
162
211
 
163
212
  context 'abbreviated' do
@@ -165,6 +214,8 @@ describe FlexYear do
165
214
  its(:year_low) { should eq(1972) }
166
215
  its(:year_high) { should eq(1974) }
167
216
  its(:decade?) { should eq(false) }
217
+ its(:decade) { should eq("1970s") }
218
+ its(:decades) { should be_nil }
168
219
  end
169
220
 
170
221
  context 'with dots' do
@@ -172,6 +223,8 @@ describe FlexYear do
172
223
  its(:year_low) { should eq(1972) }
173
224
  its(:year_high) { should eq(1974) }
174
225
  its(:decade?) { should eq(false) }
226
+ its(:decade) { should eq("1970s") }
227
+ its(:decades) { should be_nil }
175
228
  end
176
229
 
177
230
  context 'with c.' do
@@ -179,6 +232,8 @@ describe FlexYear do
179
232
  its(:year_low) { should eq(1972) }
180
233
  its(:year_high) { should eq(1974) }
181
234
  its(:decade?) { should eq(false) }
235
+ its(:decade) { should eq("1970s") }
236
+ its(:decades) { should be_nil }
182
237
  end
183
238
 
184
239
  context 'with ca.' do
@@ -186,6 +241,8 @@ describe FlexYear do
186
241
  its(:year_low) { should eq(1972) }
187
242
  its(:year_high) { should eq(1974) }
188
243
  its(:decade?) { should eq(false) }
244
+ its(:decade) { should eq("1970s") }
245
+ its(:decades) { should be_nil }
189
246
  end
190
247
 
191
248
  context 'with approx.' do
@@ -193,6 +250,8 @@ describe FlexYear do
193
250
  its(:year_low) { should eq(1972) }
194
251
  its(:year_high) { should eq(1974) }
195
252
  its(:decade?) { should eq(false) }
253
+ its(:decade) { should eq("1970s") }
254
+ its(:decades) { should be_nil }
196
255
  end
197
256
 
198
257
  context 'with appxly.' do
@@ -200,6 +259,8 @@ describe FlexYear do
200
259
  its(:year_low) { should eq(1972) }
201
260
  its(:year_high) { should eq(1974) }
202
261
  its(:decade?) { should eq(false) }
262
+ its(:decade) { should eq("1970s") }
263
+ its(:decades) { should be_nil }
203
264
  end
204
265
 
205
266
  context 'with around' do
@@ -207,6 +268,8 @@ describe FlexYear do
207
268
  its(:year_low) { should eq(1972) }
208
269
  its(:year_high) { should eq(1974) }
209
270
  its(:decade?) { should eq(false) }
271
+ its(:decade) { should eq("1970s") }
272
+ its(:decades) { should be_nil }
210
273
  end
211
274
 
212
275
  context 'with about' do
@@ -214,6 +277,8 @@ describe FlexYear do
214
277
  its(:year_low) { should eq(1972) }
215
278
  its(:year_high) { should eq(1974) }
216
279
  its(:decade?) { should eq(false) }
280
+ its(:decade) { should eq("1970s") }
281
+ its(:decades) { should be_nil }
217
282
  end
218
283
 
219
284
  context 'with circ' do
@@ -221,6 +286,8 @@ describe FlexYear do
221
286
  its(:year_low) { should eq(1972) }
222
287
  its(:year_high) { should eq(1974) }
223
288
  its(:decade?) { should eq(false) }
289
+ its(:decade) { should eq("1970s") }
290
+ its(:decades) { should be_nil }
224
291
  end
225
292
 
226
293
  context 'with cca' do
@@ -228,6 +295,8 @@ describe FlexYear do
228
295
  its(:year_low) { should eq(1972) }
229
296
  its(:year_high) { should eq(1974) }
230
297
  its(:decade?) { should eq(false) }
298
+ its(:decade) { should eq("1970s") }
299
+ its(:decades) { should be_nil }
231
300
  end
232
301
 
233
302
  context 'given 2 character fields' do
@@ -236,6 +305,8 @@ describe FlexYear do
236
305
  its(:year_low) { should eq(1973) }
237
306
  its(:year_high) { should eq(1973) }
238
307
  its(:decade?) { should eq(false) }
308
+ its(:decade) { should eq("1970s") }
309
+ its(:decades) { should be_nil }
239
310
  end
240
311
 
241
312
  context "from current century" do
@@ -243,30 +314,38 @@ describe FlexYear do
243
314
  its(:year_low) { should eq(2006) }
244
315
  its(:year_high) { should eq(2006) }
245
316
  its(:decade?) { should eq(false) }
317
+ its(:decade) { should eq("2000s") }
318
+ its(:decades) { should be_nil }
246
319
  end
247
320
  end
248
321
  end
249
322
 
250
323
  context "given a list" do
251
324
  context "mixed years" do
252
- subject { flexyear_class.new(["1980s", "mid-80s", "1988 - 1999", 2001,]) }
325
+ subject { flexyear_class.new(["1980s", "mid-80s", "1988 - 1999", 2001, "199*"]) }
253
326
  its(:year_low) { should eq(1980) }
254
327
  its(:year_high) { should eq(2001) }
255
- its(:decade?) { should eq(false) }
328
+ its(:decade?) { should eq(false) }
329
+ its(:decade) { should be_nil }
330
+ its(:decades) { should eq(["1980s", "1980s", nil, "2000s", "1990s"])}
256
331
  end
257
332
 
258
333
  context "same years" do
259
334
  subject { flexyear_class.new(["1988", "1988"]) }
260
335
  its(:year_low) { should eq(1988) }
261
336
  its(:year_high) { should eq(1988) }
262
- its(:decade?) { should eq(false) }
337
+ its(:decade?) { should eq(false) }
338
+ its(:decade) { should be_nil }
339
+ its(:decades) { should eq(["1980s", "1980s"])}
263
340
  end
264
341
 
265
342
  context "mixed years with nil" do
266
343
  subject { flexyear_class.new(["1988", "1990s", nil]) }
267
344
  its(:year_low) { should eq(1988) }
268
345
  its(:year_high) { should eq(1999) }
269
- its(:decade?) { should eq(false) }
346
+ its(:decade?) { should eq(false) }
347
+ its(:decade) { should be_nil }
348
+ its(:decades) { should eq(["1980s", "1990s", nil])}
270
349
  end
271
350
  end
272
351
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexyear
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Melnick & Yan Pritzker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-30 00:00:00.000000000 Z
11
+ date: 2019-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements: []
118
118
  rubyforge_project:
119
- rubygems_version: 2.4.5
119
+ rubygems_version: 2.5.2.3
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Natural language year range parser