flexyear 1.0.0 → 1.0.1

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: c675039dfb05f1a30e363fc530c26494f0ba16a4
4
- data.tar.gz: 5b64c416f727efb0a6e6e7626f06329dcc924e85
3
+ metadata.gz: 6c016a8105451d1e6531aad3a1a414c29e96ea58
4
+ data.tar.gz: 30c971747ad7fa88e014ce3a398b1acc0736cf4a
5
5
  SHA512:
6
- metadata.gz: 648190b1135fad334615fff61b97bdf6f9e628839b9191adb3da2ba157d54d315b8e82bf0cc4ca224ee947e85ec735d0182348376bfa7c3c6a15d69851b47a9a
7
- data.tar.gz: 8d9810c0aab0b64d1883008a0714b93061c695e6de2ea9f295f2a3a7ed33755be873c55d567401b6b2996cf8aa1cb2bb58ebae9d57d3f0dd2ab5872e9e9ec1fa
6
+ metadata.gz: 216677db5ea78483ff7b8f0f4b03b7945fc71eefd3ef9de8578a7671da6aa4e7d62f29bc8a92aa59f15ef96fcd9718b198999b2fce3e3ae8989575911fa9239a
7
+ data.tar.gz: c6435aaf570feb823d3c14f0c747b8768a9d2cac8e203227e587a2c8b3f70ed212bf0e81b3fbec38440c63d947d8a54ab8dad8a8776cfd6e5d9087b4ff753589
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .ruby-*
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/lib/flexyear.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'flexyear/range_parsers/range_parser'
2
+ require 'flexyear/range_parsers/asterisk_parser'
2
3
  require 'flexyear/range_parsers/early_parser'
3
4
  require 'flexyear/range_parsers/mid_parser'
4
5
  require 'flexyear/range_parsers/late_parser'
@@ -54,13 +55,15 @@ class FlexYear
54
55
  end
55
56
 
56
57
  def parse_year
57
- if @year_string =~ /(\d+)\s*-\s*(\d+)/ && $1 && $2
58
+ if @year_string =~ range_regex && $1 && $2
58
59
  @year_low = centuryize($1).to_i
59
60
  @year_low, @year_high = [@year_low, centuryize($2, @year_low).to_i].sort
60
61
  else
61
- if @year_string =~ /(\d+).*s$/
62
+ if @year_string =~ decade_regex
62
63
  @base_year = centuryize($1).to_i
63
- elsif @year_string =~ /^\w+\s+(\d+)/
64
+ elsif @year_string =~ asterisk_regex
65
+ @base_year = centuryize($1).to_i * 10
66
+ elsif @year_string =~ starts_with_word_regex
64
67
  @base_year = centuryize($1).to_i
65
68
  else
66
69
  @base_year = @year_string.gsub(/\D+/,'').to_i
@@ -75,6 +78,22 @@ class FlexYear
75
78
  end
76
79
  end
77
80
 
81
+ def range_regex
82
+ /(\d+)\s*-\s*(\d+)/
83
+ end
84
+
85
+ def asterisk_regex
86
+ /(\d+).*\*$/
87
+ end
88
+
89
+ def decade_regex
90
+ /(\d+).*s$/
91
+ end
92
+
93
+ def starts_with_word_regex
94
+ /^\w+\s+(\d+)/
95
+ end
96
+
78
97
  # Represents a flexible year entry that must be in the past.
79
98
  class Historical < FlexYear
80
99
  private
@@ -0,0 +1,11 @@
1
+ class FlexYear
2
+ class AsteriskParser < RangeParser
3
+ def self.can_parse?(string)
4
+ string.end_with?('*')
5
+ end
6
+
7
+ def parse
8
+ [0, 9]
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  class FlexYear
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -32,6 +32,12 @@ describe FlexYear do
32
32
  its(:year_high) { should eq(1979) }
33
33
  end
34
34
 
35
+ context 'given 197*' do
36
+ subject { flexyear_class.new('197*') }
37
+ its(:year_low) { should eq(1970) }
38
+ its(:year_high) { should eq(1979) }
39
+ end
40
+
35
41
  context "given 1970s" do
36
42
  subject { flexyear_class.new("1970s") }
37
43
  its(:year_low) { should eq(1970) }
@@ -49,13 +55,13 @@ describe FlexYear do
49
55
  its(:year_low) { should eq(2005) }
50
56
  its(:year_high) { should eq(2007) }
51
57
  end
52
-
58
+
53
59
  context 'given before 1973' do
54
60
  subject { FlexYear.new('before 1973') }
55
61
  its(:year_low) { should be_nil }
56
62
  its(:year_high) { should eq(1973) }
57
63
  end
58
-
64
+
59
65
  context 'given after 1973' do
60
66
  subject { FlexYear.new('after 1973') }
61
67
  its(:year_low) { should eq(1973) }
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexyear
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
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-10-01 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
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
54
  version: '0'
55
55
  description: Parse common year range formats like '1973-75' or natural language ranges
@@ -60,7 +60,9 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
63
+ - ".gitignore"
64
+ - ".ruby-gemset"
65
+ - ".ruby-version"
64
66
  - CHANGELOG
65
67
  - Gemfile
66
68
  - LICENSE.txt
@@ -69,6 +71,7 @@ files:
69
71
  - flexyear.gemspec
70
72
  - lib/flexyear.rb
71
73
  - lib/flexyear/range_parsers/after_parser.rb
74
+ - lib/flexyear/range_parsers/asterisk_parser.rb
72
75
  - lib/flexyear/range_parsers/before_parser.rb
73
76
  - lib/flexyear/range_parsers/circa_parser.rb
74
77
  - lib/flexyear/range_parsers/decade_parser.rb
@@ -90,17 +93,17 @@ require_paths:
90
93
  - lib
91
94
  required_ruby_version: !ruby/object:Gem::Requirement
92
95
  requirements:
93
- - - '>='
96
+ - - ">="
94
97
  - !ruby/object:Gem::Version
95
98
  version: '0'
96
99
  required_rubygems_version: !ruby/object:Gem::Requirement
97
100
  requirements:
98
- - - '>='
101
+ - - ">="
99
102
  - !ruby/object:Gem::Version
100
103
  version: '0'
101
104
  requirements: []
102
105
  rubyforge_project:
103
- rubygems_version: 2.0.0
106
+ rubygems_version: 2.1.11
104
107
  signing_key:
105
108
  specification_version: 4
106
109
  summary: Natural language year range parser