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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c600ec9615d1a122bb9a76973bfaaa44c38e9b38
4
- data.tar.gz: 60878b3ded358e15414b064e64266aadcde5b22c
3
+ metadata.gz: c675039dfb05f1a30e363fc530c26494f0ba16a4
4
+ data.tar.gz: 5b64c416f727efb0a6e6e7626f06329dcc924e85
5
5
  SHA512:
6
- metadata.gz: faa9538ccd247cad361ccaa8d7061e0d5850a274a46f5f1b90e24d7472cd14234e7c8926482955ba123c76f65450e2b457a73ffbcbac823595bd45949ff7e4f8
7
- data.tar.gz: 631f4828f79dd5e188ae9a81774c4ce6a18f3406427b104267eb86f12b4825fa255d15a1633c3f8d46fd85181068aa5cf15b79db8d33e85e227f9ce36a1b70e7
6
+ metadata.gz: 648190b1135fad334615fff61b97bdf6f9e628839b9191adb3da2ba157d54d315b8e82bf0cc4ca224ee947e85ec735d0182348376bfa7c3c6a15d69851b47a9a
7
+ data.tar.gz: 8d9810c0aab0b64d1883008a0714b93061c695e6de2ea9f295f2a3a7ed33755be873c55d567401b6b2996cf8aa1cb2bb58ebae9d57d3f0dd2ab5872e9e9ec1fa
@@ -0,0 +1,11 @@
1
+ class FlexYear
2
+ class AfterParser < RangeParser
3
+ def self.can_parse?(string)
4
+ string.start_with?('after')
5
+ end
6
+
7
+ def parse
8
+ [0, nil]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class FlexYear
2
+ class BeforeParser < RangeParser
3
+ def self.can_parse?(string)
4
+ string.start_with?('before')
5
+ end
6
+
7
+ def parse
8
+ [nil, 0]
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  class FlexYear
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
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 + (@low || 0)
72
- @year_high = @base_year + (@high || 0)
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 #{@base_year}; Today is #{DateTime.now.year}"
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
@@ -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 eq(0) }
8
- its(:year_high) { should eq(0) }
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 eq(0) }
14
- its(:year_high) { should eq(0) }
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 eq(0) }
20
- its(:year_high) { should eq(0) }
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.3
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-08-24 00:00:00.000000000 Z
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: