flexyear 2.3.0 → 2.4.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
- SHA1:
3
- metadata.gz: 9e9174d74ff69cacee7ce260b97f5d078df55504
4
- data.tar.gz: 4b24e5c479bb602a2622f5460ec391cd0ef17390
2
+ SHA256:
3
+ metadata.gz: 76222dec0e41ccbd4cfae4dd0d6ce3372790ae0ff9f1a0454b7003b663d03f1a
4
+ data.tar.gz: 9ae27ce940ba0e5b8e5258c7e4ccc2b405913b077b2193eef32ff7f5ca8f1702
5
5
  SHA512:
6
- metadata.gz: 0d18648d7172c4accb880dc63047fedfc590e7c5d76ca74f42a60279aad65e8e790a238612bccd69d8dadd2f15e7eabc0b04ec5ef100a8a8a88c71231e8e7ea1
7
- data.tar.gz: 534ea4c77aaec2aa1ef32661c92472ced07f5817a44773b1da7c7867be5971e61037a777aa5319b8f1797f6e64dd499193a21687a200b6a3f53f1f071980806e
6
+ metadata.gz: b375a2c188636a09b4598e0141649112d4845485b3c618061d86cdc16a099ccbf5aee9c5b51b84b5a9a5d8b58cffa52219b8cedd15fa8ea26aac8d610f051fb3
7
+ data.tar.gz: 1264dbafb0d737569bde093983260a23bb1d0f8468ad09ecf1d4d3b6a31a9c6eb437717cebe49e6810511052682023daede11376f28ee306b81e54aa989ed88a
@@ -1,3 +1,3 @@
1
1
  class FlexYear
2
- VERSION = "2.3.0"
2
+ VERSION = "2.4.0"
3
3
  end
data/lib/flexyear.rb CHANGED
@@ -67,7 +67,7 @@ class FlexYear
67
67
  [year.year_low, year.year_high]
68
68
  end
69
69
 
70
- flat_years = all_years.compact.uniq
70
+ flat_years = all_years.uniq.map { |y| y.nil? ? Date.today.year : y }
71
71
 
72
72
  @year_low = flat_years.min
73
73
  @year_high = flat_years.max
@@ -110,6 +110,9 @@ class FlexYear
110
110
  if year_string =~ range_regex && $1 && $2
111
111
  @year_low = centuryize($1).to_i
112
112
  @year_low, @year_high = [@year_low, centuryize($2, @year_low).to_i].sort
113
+ elsif year_string =~ open_ended_range_regex
114
+ @year_low = centuryize($1).to_i
115
+ @year_high = Date.today.year
113
116
  else
114
117
  if year_string =~ decade_regex
115
118
  @base_year = centuryize($1).to_i
@@ -134,6 +137,10 @@ class FlexYear
134
137
  /(\d+)\s*-\s*(\d+)/
135
138
  end
136
139
 
140
+ def open_ended_range_regex
141
+ /(\d+)\s*-\s*(\D+)/
142
+ end
143
+
137
144
  def asterisk_regex
138
145
  /(\d+).*\*$/
139
146
  end
@@ -170,6 +170,15 @@ describe FlexYear do
170
170
  its(:decades) { should be_nil }
171
171
  end
172
172
 
173
+ context "given a range from a year to present" do
174
+ subject { flexyear_class.new('1975-Present') }
175
+ its(:year_low) { should eq(1975) }
176
+ its(:year_high) { should eq(2016) }
177
+ its(:decade?) { should eq(false) }
178
+ its(:decade) { should be_nil }
179
+ its(:decades) { should be_nil }
180
+ end
181
+
173
182
  context "given a range in difference decades" do
174
183
  subject { flexyear_class.new('1975-1983') }
175
184
  its(:year_low) { should eq(1975) }
@@ -342,11 +351,20 @@ describe FlexYear do
342
351
  context "mixed years with nil" do
343
352
  subject { flexyear_class.new(["1988", "1990s", nil]) }
344
353
  its(:year_low) { should eq(1988) }
345
- its(:year_high) { should eq(1999) }
354
+ its(:year_high) { should eq(2016) }
346
355
  its(:decade?) { should eq(false) }
347
356
  its(:decade) { should be_nil }
348
357
  its(:decades) { should eq(["1980s", "1990s", nil])}
349
358
  end
359
+
360
+ context "with a year with an undefined end date" do
361
+ subject { flexyear_class.new(["1980s", "mid-80s", "1988 - 1999", 2001, "199*", "1999 - Present"]) }
362
+ its(:year_low) { should eq(1980) }
363
+ its(:year_high) { should eq(2016) }
364
+ its(:decade?) { should eq(false) }
365
+ its(:decade) { should be_nil }
366
+ its(:decades) { should eq(["1980s", "1980s", nil, "2000s", "1990s", nil])}
367
+ end
350
368
  end
351
369
 
352
370
  context "given 12345 (five digit year)" do
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.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Melnick & Yan Pritzker
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-09 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,7 +100,7 @@ homepage: http://github.com/reverbdotcom/flexyear
100
100
  licenses:
101
101
  - MIT
102
102
  metadata: {}
103
- post_install_message:
103
+ post_install_message:
104
104
  rdoc_options: []
105
105
  require_paths:
106
106
  - lib
@@ -115,9 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 2.5.2.3
120
- signing_key:
118
+ rubygems_version: 3.1.6
119
+ signing_key:
121
120
  specification_version: 4
122
121
  summary: Natural language year range parser
123
122
  test_files: