flexyear 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/lib/flexyear.rb +1 -1
- data/lib/flexyear/version.rb +1 -1
- data/spec/flexyear_spec.rb +142 -139
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c600ec9615d1a122bb9a76973bfaaa44c38e9b38
|
4
|
+
data.tar.gz: 60878b3ded358e15414b064e64266aadcde5b22c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faa9538ccd247cad361ccaa8d7061e0d5850a274a46f5f1b90e24d7472cd14234e7c8926482955ba123c76f65450e2b457a73ffbcbac823595bd45949ff7e4f8
|
7
|
+
data.tar.gz: 631f4828f79dd5e188ae9a81774c4ce6a18f3406427b104267eb86f12b4825fa255d15a1633c3f8d46fd85181068aa5cf15b79db8d33e85e227f9ce36a1b70e7
|
data/CHANGELOG
CHANGED
data/lib/flexyear.rb
CHANGED
@@ -80,7 +80,7 @@ class FlexYear
|
|
80
80
|
def parse_year
|
81
81
|
super
|
82
82
|
|
83
|
-
if @
|
83
|
+
if @year_low > DateTime.now.year || @year_high > DateTime.now.year
|
84
84
|
raise InvalidYearError, "The year must be in the past. You specified #{@base_year}; Today is #{DateTime.now.year}"
|
85
85
|
end
|
86
86
|
end
|
data/lib/flexyear/version.rb
CHANGED
data/spec/flexyear_spec.rb
CHANGED
@@ -1,179 +1,181 @@
|
|
1
1
|
require 'flexyear'
|
2
2
|
|
3
3
|
describe FlexYear do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
context "given nil" do
|
11
|
-
subject { FlexYear.new(nil) }
|
12
|
-
its(:year_low) { should eq(0) }
|
13
|
-
its(:year_high) { should eq(0) }
|
14
|
-
end
|
15
|
-
|
16
|
-
context "text" do
|
17
|
-
subject { FlexYear.new("something") }
|
18
|
-
its(:year_low) { should eq(0) }
|
19
|
-
its(:year_high) { should eq(0) }
|
20
|
-
end
|
21
|
-
|
22
|
-
context "given 1979 as number" do
|
23
|
-
subject { FlexYear.new(1979) }
|
24
|
-
its(:year_low) { should eq(1979) }
|
25
|
-
its(:year_high) { should eq(1979) }
|
26
|
-
end
|
27
|
-
|
28
|
-
context "given 1979" do
|
29
|
-
subject { FlexYear.new("1979") }
|
30
|
-
its(:year_low) { should eq(1979) }
|
31
|
-
its(:year_high) { should eq(1979) }
|
32
|
-
end
|
4
|
+
[FlexYear, FlexYear::Historical].each do |flexyear_class|
|
5
|
+
context "given a blank string" do
|
6
|
+
subject { flexyear_class.new("") }
|
7
|
+
its(:year_low) { should eq(0) }
|
8
|
+
its(:year_high) { should eq(0) }
|
9
|
+
end
|
33
10
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
11
|
+
context "given nil" do
|
12
|
+
subject { flexyear_class.new(nil) }
|
13
|
+
its(:year_low) { should eq(0) }
|
14
|
+
its(:year_high) { should eq(0) }
|
15
|
+
end
|
39
16
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
17
|
+
context "text" do
|
18
|
+
subject { flexyear_class.new("something") }
|
19
|
+
its(:year_low) { should eq(0) }
|
20
|
+
its(:year_high) { should eq(0) }
|
21
|
+
end
|
45
22
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
23
|
+
context "given 1979 as number" do
|
24
|
+
subject { flexyear_class.new(1979) }
|
25
|
+
its(:year_low) { should eq(1979) }
|
26
|
+
its(:year_high) { should eq(1979) }
|
27
|
+
end
|
51
28
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
its(:
|
56
|
-
its(:year_high) { should eq(1976) }
|
57
|
-
its(:to_s) { should eq(year) }
|
29
|
+
context "given 1979" do
|
30
|
+
subject { flexyear_class.new("1979") }
|
31
|
+
its(:year_low) { should eq(1979) }
|
32
|
+
its(:year_high) { should eq(1979) }
|
58
33
|
end
|
59
|
-
end
|
60
34
|
|
61
|
-
|
62
|
-
|
63
|
-
subject { FlexYear.new(year) }
|
35
|
+
context "given 1970s" do
|
36
|
+
subject { flexyear_class.new("1970s") }
|
64
37
|
its(:year_low) { should eq(1970) }
|
65
|
-
its(:year_high) { should eq(
|
38
|
+
its(:year_high) { should eq(1979) }
|
66
39
|
end
|
67
|
-
end
|
68
40
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
its(:year_low) { should eq(1976) }
|
41
|
+
context "given 70s" do
|
42
|
+
subject { flexyear_class.new("70s") }
|
43
|
+
its(:year_low) { should eq(1970) }
|
73
44
|
its(:year_high) { should eq(1979) }
|
74
45
|
end
|
75
|
-
end
|
76
46
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
its(:
|
81
|
-
its(:year_high) { should eq(1975) }
|
47
|
+
context "given something with negative and dots" do
|
48
|
+
subject { flexyear_class.new("approx.-2006") }
|
49
|
+
its(:year_low) { should eq(2005) }
|
50
|
+
its(:year_high) { should eq(2007) }
|
82
51
|
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "given a range 1975-1973 (from high to low)" do
|
86
|
-
subject { FlexYear.new('1975-1973') }
|
87
|
-
its(:year_low) { should eq(1973) }
|
88
|
-
its(:year_high) { should eq(1975) }
|
89
|
-
end
|
90
52
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
53
|
+
["mid 1970s", "mid 70s", "mid-70s", "mid-70's"].each do |year|
|
54
|
+
context "given #{year}" do
|
55
|
+
subject { flexyear_class.new(year) }
|
56
|
+
its(:year_low) { should eq(1973) }
|
57
|
+
its(:year_high) { should eq(1976) }
|
58
|
+
its(:to_s) { should eq(year) }
|
59
|
+
end
|
96
60
|
end
|
97
|
-
end
|
98
61
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
62
|
+
["early 1970s", "early 70s", "early-70s", "early 70's"].each do |year|
|
63
|
+
context "given #{year}" do
|
64
|
+
subject { flexyear_class.new(year) }
|
65
|
+
its(:year_low) { should eq(1970) }
|
66
|
+
its(:year_high) { should eq(1973) }
|
67
|
+
end
|
104
68
|
end
|
105
69
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
70
|
+
["late 1970s", "late 70s", "late -70s", "late 70 s"].each do |year|
|
71
|
+
context "given #{year}" do
|
72
|
+
subject { flexyear_class.new(year) }
|
73
|
+
its(:year_low) { should eq(1976) }
|
74
|
+
its(:year_high) { should eq(1979) }
|
75
|
+
end
|
110
76
|
end
|
111
77
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
78
|
+
["73-75", "1973-1975", "1973 - 1975", "1973- 1975", "1973 -1975", "1973-75"].each do |range|
|
79
|
+
context "given a range #{range}" do
|
80
|
+
subject { flexyear_class.new(range) }
|
81
|
+
its(:year_low) { should eq(1973) }
|
82
|
+
its(:year_high) { should eq(1975) }
|
83
|
+
end
|
116
84
|
end
|
117
85
|
|
118
|
-
context
|
119
|
-
subject {
|
120
|
-
its(:year_low) { should eq(
|
121
|
-
its(:year_high) { should eq(
|
86
|
+
context "given a range 1975-1973 (from high to low)" do
|
87
|
+
subject { flexyear_class.new('1975-1973') }
|
88
|
+
its(:year_low) { should eq(1973) }
|
89
|
+
its(:year_high) { should eq(1975) }
|
122
90
|
end
|
123
91
|
|
124
|
-
context
|
125
|
-
|
126
|
-
|
127
|
-
|
92
|
+
context "given a range" do
|
93
|
+
["2003-4", "2003-04"].each do |range|
|
94
|
+
subject { flexyear_class.new(range) }
|
95
|
+
its(:year_low) { should eq(2003) }
|
96
|
+
its(:year_high) { should eq(2004) }
|
97
|
+
end
|
128
98
|
end
|
129
99
|
|
130
|
-
context '
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
100
|
+
context 'given a circa' do
|
101
|
+
context 'at the end of the string' do
|
102
|
+
subject { flexyear_class.new('1973 (Circa)') }
|
103
|
+
its(:year_low) { should eq(1972) }
|
104
|
+
its(:year_high) { should eq(1974) }
|
105
|
+
end
|
135
106
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
107
|
+
context 'at the beginning of the string' do
|
108
|
+
subject { flexyear_class.new('Circa 1973') }
|
109
|
+
its(:year_low) { should eq(1972) }
|
110
|
+
its(:year_high) { should eq(1974) }
|
111
|
+
end
|
141
112
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
113
|
+
context 'abbreviated' do
|
114
|
+
subject { flexyear_class.new('ca 1973') }
|
115
|
+
its(:year_low) { should eq(1972) }
|
116
|
+
its(:year_high) { should eq(1974) }
|
117
|
+
end
|
147
118
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
119
|
+
context 'with dots' do
|
120
|
+
subject { flexyear_class.new('c.a. 1973') }
|
121
|
+
its(:year_low) { should eq(1972) }
|
122
|
+
its(:year_high) { should eq(1974) }
|
123
|
+
end
|
153
124
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
125
|
+
context 'with c.' do
|
126
|
+
subject { flexyear_class.new('c. 1973') }
|
127
|
+
its(:year_low) { should eq(1972) }
|
128
|
+
its(:year_high) { should eq(1974) }
|
129
|
+
end
|
159
130
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
131
|
+
context 'with ca.' do
|
132
|
+
subject { flexyear_class.new('ca. 1973') }
|
133
|
+
its(:year_low) { should eq(1972) }
|
134
|
+
its(:year_high) { should eq(1974) }
|
135
|
+
end
|
165
136
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
137
|
+
context 'with approx.' do
|
138
|
+
subject { flexyear_class.new('approx. 1973') }
|
139
|
+
its(:year_low) { should eq(1972) }
|
140
|
+
its(:year_high) { should eq(1974) }
|
141
|
+
end
|
171
142
|
|
172
|
-
|
143
|
+
context 'with appxly.' do
|
144
|
+
subject { flexyear_class.new('appxly 1973') }
|
145
|
+
its(:year_low) { should eq(1972) }
|
146
|
+
its(:year_high) { should eq(1974) }
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'with around' do
|
150
|
+
subject { flexyear_class.new('around 1973') }
|
151
|
+
its(:year_low) { should eq(1972) }
|
152
|
+
its(:year_high) { should eq(1974) }
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'with about' do
|
156
|
+
subject { flexyear_class.new('about 1973') }
|
157
|
+
its(:year_low) { should eq(1972) }
|
158
|
+
its(:year_high) { should eq(1974) }
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'with circ' do
|
162
|
+
subject { flexyear_class.new('circ. 1973') }
|
163
|
+
its(:year_low) { should eq(1972) }
|
164
|
+
its(:year_high) { should eq(1974) }
|
165
|
+
end
|
166
|
+
|
167
|
+
context 'with cca' do
|
168
|
+
subject { flexyear_class.new('cca 1973') }
|
169
|
+
its(:year_low) { should eq(1972) }
|
170
|
+
its(:year_high) { should eq(1974) }
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
173
174
|
|
174
|
-
|
175
|
-
|
176
|
-
|
175
|
+
context "given 12345 (five digit year)" do
|
176
|
+
specify do
|
177
|
+
expect { flexyear_class.new('12345') }.to raise_error(FlexYear::InvalidYearError)
|
178
|
+
end
|
177
179
|
end
|
178
180
|
end
|
179
181
|
|
@@ -184,4 +186,5 @@ describe FlexYear do
|
|
184
186
|
end
|
185
187
|
end
|
186
188
|
end
|
189
|
+
|
187
190
|
end
|
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: 0.0.3
|
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-
|
11
|
+
date: 2013-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|