flexyear 1.0.1 → 2.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: 6c016a8105451d1e6531aad3a1a414c29e96ea58
4
- data.tar.gz: 30c971747ad7fa88e014ce3a398b1acc0736cf4a
3
+ metadata.gz: 97cfa33d0a581edde9231e9179dcf15b4961886f
4
+ data.tar.gz: 28a10f8c6506e5aec3b1682e7bec4985cc6cd01b
5
5
  SHA512:
6
- metadata.gz: 216677db5ea78483ff7b8f0f4b03b7945fc71eefd3ef9de8578a7671da6aa4e7d62f29bc8a92aa59f15ef96fcd9718b198999b2fce3e3ae8989575911fa9239a
7
- data.tar.gz: c6435aaf570feb823d3c14f0c747b8768a9d2cac8e203227e587a2c8b3f70ed212bf0e81b3fbec38440c63d947d8a54ab8dad8a8776cfd6e5d9087b4ff753589
6
+ metadata.gz: 239b899a0be17549545621a5aa099c21b592cffdb0d442200ff9567be24aad59d78e27cfd99b8760f0612574fba2c2e6875515db6a2e512604d0d1ea926b71d7
7
+ data.tar.gz: f5045399981aac58a22aca47326d6cff185928943be452c256535aa95511a885ba984a9cbcad3bfa2ab1804ab56957d72ab11a2de1f0c46dccd7cae3833e2c06
data/flexyear.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["pair+dm+yp@reverb.com"]
11
11
  spec.description = %q{Parse common year range formats like '1973-75' or natural language ranges like 'mid 80s'}
12
12
  spec.summary = %q{Natural language year range parser}
13
- spec.homepage = "http://github.com/reverbdev/flexyear"
13
+ spec.homepage = "http://github.com/reverbdotcom/flexyear"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -20,5 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "rspec", "~> 3.5"
24
+ spec.add_development_dependency "rspec-its", "~> 1.2"
24
25
  end
@@ -1,3 +1,3 @@
1
1
  class FlexYear
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/flexyear.rb CHANGED
@@ -40,7 +40,7 @@ class FlexYear
40
40
  private
41
41
 
42
42
  def centuryize(year, base_year=nil)
43
- base = "19" # 19th century
43
+ base = default_base_year(year)
44
44
  if base_year
45
45
  base = (base_year/100).to_s
46
46
  end
@@ -54,6 +54,15 @@ class FlexYear
54
54
  end
55
55
  end
56
56
 
57
+ def default_base_year(year)
58
+ current_year = Date.today.year.to_s
59
+ if year.to_i < current_year[-2..-1].to_i
60
+ "20" # 21st century
61
+ else
62
+ "19" # 20th century
63
+ end
64
+ end
65
+
57
66
  def parse_year
58
67
  if @year_string =~ range_regex && $1 && $2
59
68
  @year_low = centuryize($1).to_i
@@ -66,7 +75,7 @@ class FlexYear
66
75
  elsif @year_string =~ starts_with_word_regex
67
76
  @base_year = centuryize($1).to_i
68
77
  else
69
- @base_year = @year_string.gsub(/\D+/,'').to_i
78
+ @base_year = centuryize(@year_string.gsub(/\D+/,'')).to_i
70
79
  end
71
80
 
72
81
  if @base_year > 9999
@@ -1,6 +1,12 @@
1
+ require "rspec"
2
+ require "rspec/its"
1
3
  require 'flexyear'
2
4
 
3
5
  describe FlexYear do
6
+ before do
7
+ allow(Date).to receive(:today) { Date.parse("2016-11-07") }
8
+ end
9
+
4
10
  [FlexYear, FlexYear::Historical].each do |flexyear_class|
5
11
  context "given a blank string" do
6
12
  subject { flexyear_class.new("") }
@@ -108,7 +114,7 @@ describe FlexYear do
108
114
  end
109
115
 
110
116
  context "given a range" do
111
- ["2003-4", "2003-04"].each do |range|
117
+ ["2003-4", "2003-04", "03-04"].each do |range|
112
118
  subject { flexyear_class.new(range) }
113
119
  its(:year_low) { should eq(2003) }
114
120
  its(:year_high) { should eq(2004) }
@@ -188,6 +194,19 @@ describe FlexYear do
188
194
  its(:year_high) { should eq(1974) }
189
195
  end
190
196
 
197
+ context 'given 2 character fields' do
198
+ context "from previous century" do
199
+ subject { flexyear_class.new("73") }
200
+ its(:year_low) { should eq(1973) }
201
+ its(:year_high) { should eq(1973) }
202
+ end
203
+
204
+ context "from current century" do
205
+ subject { flexyear_class.new("06") }
206
+ its(:year_low) { should eq(2006) }
207
+ its(:year_high) { should eq(2006) }
208
+ end
209
+ end
191
210
  end
192
211
 
193
212
  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: 1.0.1
4
+ version: 2.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: 2014-04-28 00:00:00.000000000 Z
11
+ date: 2016-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,30 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
55
69
  description: Parse common year range formats like '1973-75' or natural language ranges
56
70
  like 'mid 80s'
57
71
  email:
@@ -83,7 +97,7 @@ files:
83
97
  - lib/flexyear/range_parsers/year_range_parser.rb
84
98
  - lib/flexyear/version.rb
85
99
  - spec/flexyear_spec.rb
86
- homepage: http://github.com/reverbdev/flexyear
100
+ homepage: http://github.com/reverbdotcom/flexyear
87
101
  licenses:
88
102
  - MIT
89
103
  metadata: {}
@@ -103,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
117
  version: '0'
104
118
  requirements: []
105
119
  rubyforge_project:
106
- rubygems_version: 2.1.11
120
+ rubygems_version: 2.2.2
107
121
  signing_key:
108
122
  specification_version: 4
109
123
  summary: Natural language year range parser