flexyear 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flexyear/range_parsers/after_parser.rb +11 -0
- data/lib/flexyear/range_parsers/before_parser.rb +11 -0
- data/lib/flexyear/version.rb +1 -1
- data/lib/flexyear.rb +6 -4
- data/spec/flexyear_spec.rb +18 -6
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c675039dfb05f1a30e363fc530c26494f0ba16a4
|
4
|
+
data.tar.gz: 5b64c416f727efb0a6e6e7626f06329dcc924e85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 648190b1135fad334615fff61b97bdf6f9e628839b9191adb3da2ba157d54d315b8e82bf0cc4ca224ee947e85ec735d0182348376bfa7c3c6a15d69851b47a9a
|
7
|
+
data.tar.gz: 8d9810c0aab0b64d1883008a0714b93061c695e6de2ea9f295f2a3a7ed33755be873c55d567401b6b2996cf8aa1cb2bb58ebae9d57d3f0dd2ab5872e9e9ec1fa
|
data/lib/flexyear/version.rb
CHANGED
data/lib/flexyear.rb
CHANGED
@@ -2,6 +2,8 @@ require 'flexyear/range_parsers/range_parser'
|
|
2
2
|
require 'flexyear/range_parsers/early_parser'
|
3
3
|
require 'flexyear/range_parsers/mid_parser'
|
4
4
|
require 'flexyear/range_parsers/late_parser'
|
5
|
+
require 'flexyear/range_parsers/after_parser'
|
6
|
+
require 'flexyear/range_parsers/before_parser'
|
5
7
|
require 'flexyear/range_parsers/decade_parser'
|
6
8
|
require 'flexyear/range_parsers/year_range_parser'
|
7
9
|
require 'flexyear/range_parsers/circa_parser'
|
@@ -68,8 +70,8 @@ class FlexYear
|
|
68
70
|
raise InvalidYearError, "Please use a four digit year."
|
69
71
|
end
|
70
72
|
|
71
|
-
@year_low = @base_year +
|
72
|
-
@year_high = @base_year +
|
73
|
+
@year_low = @base_year + @low unless @low.nil?
|
74
|
+
@year_high = @base_year + @high unless @high.nil?
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
@@ -80,8 +82,8 @@ class FlexYear
|
|
80
82
|
def parse_year
|
81
83
|
super
|
82
84
|
|
83
|
-
if @year_low > DateTime.now.year || @year_high > DateTime.now.year
|
84
|
-
raise InvalidYearError, "The year must be in the past. You specified #{@
|
85
|
+
if (!@year_low.nil? && @year_low > DateTime.now.year) || (!@year_high.nil? && @year_high > DateTime.now.year)
|
86
|
+
raise InvalidYearError, "The year must be in the past. You specified #{@year_string}; Today is #{DateTime.now.year}"
|
85
87
|
end
|
86
88
|
end
|
87
89
|
end
|
data/spec/flexyear_spec.rb
CHANGED
@@ -4,20 +4,20 @@ describe FlexYear do
|
|
4
4
|
[FlexYear, FlexYear::Historical].each do |flexyear_class|
|
5
5
|
context "given a blank string" do
|
6
6
|
subject { flexyear_class.new("") }
|
7
|
-
its(:year_low) { should
|
8
|
-
its(:year_high) { should
|
7
|
+
its(:year_low) { should be_nil }
|
8
|
+
its(:year_high) { should be_nil }
|
9
9
|
end
|
10
10
|
|
11
11
|
context "given nil" do
|
12
12
|
subject { flexyear_class.new(nil) }
|
13
|
-
its(:year_low) { should
|
14
|
-
its(:year_high) { should
|
13
|
+
its(:year_low) { should be_nil }
|
14
|
+
its(:year_high) { should be_nil }
|
15
15
|
end
|
16
16
|
|
17
17
|
context "text" do
|
18
18
|
subject { flexyear_class.new("something") }
|
19
|
-
its(:year_low) { should
|
20
|
-
its(:year_high) { should
|
19
|
+
its(:year_low) { should be_nil }
|
20
|
+
its(:year_high) { should be_nil }
|
21
21
|
end
|
22
22
|
|
23
23
|
context "given 1979 as number" do
|
@@ -49,6 +49,18 @@ describe FlexYear do
|
|
49
49
|
its(:year_low) { should eq(2005) }
|
50
50
|
its(:year_high) { should eq(2007) }
|
51
51
|
end
|
52
|
+
|
53
|
+
context 'given before 1973' do
|
54
|
+
subject { FlexYear.new('before 1973') }
|
55
|
+
its(:year_low) { should be_nil }
|
56
|
+
its(:year_high) { should eq(1973) }
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'given after 1973' do
|
60
|
+
subject { FlexYear.new('after 1973') }
|
61
|
+
its(:year_low) { should eq(1973) }
|
62
|
+
its(:year_high) { should be_nil }
|
63
|
+
end
|
52
64
|
|
53
65
|
["mid 1970s", "mid 70s", "mid-70s", "mid-70's"].each do |year|
|
54
66
|
context "given #{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: 0.0
|
4
|
+
version: 1.0.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: 2013-
|
11
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,6 +68,8 @@ files:
|
|
68
68
|
- Rakefile
|
69
69
|
- flexyear.gemspec
|
70
70
|
- lib/flexyear.rb
|
71
|
+
- lib/flexyear/range_parsers/after_parser.rb
|
72
|
+
- lib/flexyear/range_parsers/before_parser.rb
|
71
73
|
- lib/flexyear/range_parsers/circa_parser.rb
|
72
74
|
- lib/flexyear/range_parsers/decade_parser.rb
|
73
75
|
- lib/flexyear/range_parsers/early_parser.rb
|
@@ -104,4 +106,3 @@ specification_version: 4
|
|
104
106
|
summary: Natural language year range parser
|
105
107
|
test_files:
|
106
108
|
- spec/flexyear_spec.rb
|
107
|
-
has_rdoc:
|