parse_date 0.3.1 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd2ee682788fbcb97d1f5e51256590401689aa3b73d1197996b3ff5344211bad
4
- data.tar.gz: b5e66c06a91ebf4db8065bd1652426485de434f873634f6e6d28a28b12efca8c
3
+ metadata.gz: b89915718c893cf65a79dfd4d589b9c1e7def99b00f56dcfee56829c5c0941e1
4
+ data.tar.gz: 96803f595b7a6d6e95f331661e48254eee0204a0d0d856bc83d46bbfe67f72a4
5
5
  SHA512:
6
- metadata.gz: 4fc0ad6ca69236e294f082cd80a9193680690d19f183210b54b71ad99edb851d2ca64d49f3df9b77b8baae3c673f0835dac4a174c65965c3282fcb7a0946b4d3
7
- data.tar.gz: 6a0b356e2be0fcb6bf427339af0cbc356f5b9b90ad070421cea7a480884ed13e269b413874559f10376bcbdd938e1837a4dfe71778a2387b427c93b958ca66c4
6
+ metadata.gz: df38bb2a88a9417f660a2e03fe642fafd3e82db85999a81d7897b8bb8577d1670a5810359bdadae0134c4edf128e4e44bcdbc59fc9bdcab94955bac2eed6afc0
7
+ data.tar.gz: a73425d3c6c2a1b8c75e4f577463ff2b321a8dc93d8f35be5318b3e58c83e2f0a3984be67397dd7a14b5380b429eb1d4e6d5edb7383c23f5b7fe94937d8379e4
@@ -17,7 +17,7 @@ Metrics/LineLength:
17
17
  Max: 120
18
18
 
19
19
  Metrics/MethodLength:
20
- Max: 22
20
+ Max: 25
21
21
 
22
22
  Style/NumericLiterals:
23
23
  Enabled: false
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-10-22 09:04:50 -0700 using RuboCop version 0.74.0.
3
+ # on 2019-10-24 13:45:33 -0700 using RuboCop version 0.74.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -8,7 +8,7 @@
8
8
 
9
9
  # Offense count: 5
10
10
  Metrics/AbcSize:
11
- Max: 37
11
+ Max: 39
12
12
 
13
13
  # Offense count: 4
14
14
  Metrics/CyclomaticComplexity:
@@ -17,7 +17,7 @@ Metrics/CyclomaticComplexity:
17
17
  # Offense count: 1
18
18
  # Configuration parameters: CountComments.
19
19
  Metrics/ModuleLength:
20
- Max: 168
20
+ Max: 176
21
21
 
22
22
  # Offense count: 4
23
23
  Metrics/PerceivedComplexity:
data/README.md CHANGED
@@ -57,6 +57,8 @@ ParseDate.parse_range('ca. 5th–6th century A.D.') # (400..599).to_a
57
57
  ParseDate.parse_range('ca. 9th–8th century B.C.') # (-999..-800).to_a
58
58
  ParseDate.parse_range('ca. 13th–12th century B.C.') # (-1399..-1200).to_a
59
59
  ParseDate.parse_range('5th century B.C.') # (-599..-500).to_a
60
+ ParseDate.parse_range('502-504') # [502, 503, 504]
61
+ ParseDate.parse_range('-2100 - -2000') # (-2100..-2000).to_a
60
62
  ParseDate.parse_range('1975 - 1905') # last year > first year, raises error
61
63
  ParseDate.parse_range('-100 - -150') # last year > first year, raises error
62
64
  ParseDate.parse_range('1975 or 1905') # last year > first year, raises error
@@ -90,6 +92,8 @@ ParseDate.earliest_year('ca. 5th–6th century A.D.') # 400
90
92
  ParseDate.earliest_year('ca. 9th–8th century B.C.') # -999
91
93
  ParseDate.earliest_year('ca. 13th–12th century B.C.') # -1399
92
94
  ParseDate.earliest_year('5th century B.C.') # -599
95
+ ParseDate.earliest_year('502-504') # 502
96
+ ParseDate.earliest_year('-2100 - -2000') # -2100
93
97
 
94
98
  ParseDate.latest_year('20000222') # 2000
95
99
  ParseDate.latest_year('195-') # 1959
@@ -113,7 +117,9 @@ ParseDate.latest_year('ca. 5th–6th century A.D.') # 599
113
117
  ParseDate.latest_year('ca. 9th–8th century B.C.') # -800
114
118
  ParseDate.latest_year('ca. 13th–12th century B.C.') # -1200
115
119
  ParseDate.latest_year('5th century B.C.') # -500
116
- ParseDate.latest_year('-5 - 3') # 3,
120
+ ParseDate.latest_year('-5 - 3') # 3
121
+ ParseDate.latest_year('502-504') # 504
122
+ ParseDate.latest_year('-2100 - -2000') # -2000
117
123
 
118
124
  ParseDate.range_array('1993', '1995') # [1993, 1994, 1995]
119
125
  ParseDate.range_array(1993, 1995) # [1993, 1994, 1995]
@@ -25,6 +25,7 @@ class ParseDate
25
25
  return ParseDate.send(:year_int_for_bc, date_str) if date_str.match(YEAR_BC_REGEX)
26
26
 
27
27
  result ||= ParseDate.send(:between_earliest_year, date_str)
28
+ result ||= ParseDate.send(:negative_first_four_digits, date_str)
28
29
  result ||= ParseDate.send(:first_four_digits, date_str)
29
30
  result ||= ParseDate.send(:year_from_mm_dd_yy, date_str)
30
31
  result ||= ParseDate.send(:first_year_for_decade, date_str) # 198x or 201x
@@ -61,6 +62,7 @@ class ParseDate
61
62
  result ||= ParseDate.send(:hyphen_2digit_latest_year, date_str)
62
63
  result ||= ParseDate.send(:yyuu_after_hyphen, date_str)
63
64
  result ||= ParseDate.send(:year_after_or, date_str)
65
+ result ||= ParseDate.send(:negative_4digits_after_hyphen, date_str)
64
66
  result ||= ParseDate.send(:first_four_digits, date_str)
65
67
  result ||= ParseDate.send(:year_from_mm_dd_yy, date_str)
66
68
  result ||= ParseDate.send(:last_year_for_decade, date_str) # 198x or 201x
@@ -75,12 +77,12 @@ class ParseDate
75
77
  result.to_i if result && year_int_valid?(result.to_i)
76
78
  end
77
79
 
78
- # true if the year is between -999 and (current year + 1), inclusive
80
+ # true if the year is between -9999 and (current year + 1), inclusive
79
81
  # @return [Boolean] true if the year is between -999 and (current year + 1); false otherwise
80
82
  def self.year_int_valid?(year)
81
83
  return false unless year.is_a? Integer
82
84
 
83
- (-1000 < year.to_i) && (year < Date.today.year + 2)
85
+ (-10000 < year.to_i) && (year < Date.today.year + 2)
84
86
  end
85
87
 
86
88
  protected
@@ -169,6 +171,18 @@ class ParseDate
169
171
  nth * -100
170
172
  end
171
173
 
174
+ # looks for -yyyy at beginning of date_str and returns if found
175
+ # @return [String, nil] negative 4 digit year (e.g. -1865) if date_str has -yyyy, nil otherwise
176
+ def negative_first_four_digits(date_str)
177
+ Regexp.last_match(1) if date_str.match(/^(\-\d{4})/)
178
+ end
179
+
180
+ # looks for -yyyy after hyphen and returns if found
181
+ # @return [String, nil] negative 4 digit year (e.g. -1865) if date_str has -yyyy - -yyyy, nil otherwise
182
+ def negative_4digits_after_hyphen(date_str)
183
+ Regexp.last_match(1) if date_str.match(/\-\d{4}\s*\-\s*(\-\d{4})/)
184
+ end
185
+
172
186
  # looks for 4 consecutive digits in date_str and returns first occurrence if found
173
187
  # @return [String, nil] 4 digit year (e.g. 1865, 0950) if date_str has yyyy, nil otherwise
174
188
  def first_four_digits(date_str)
@@ -195,7 +209,7 @@ class ParseDate
195
209
  nil # explicitly want nil if date won't parse
196
210
  end
197
211
 
198
- DECADE_4CHAR_REGEX = Regexp.new('(^|\D)\d{3}[u\-?x]', REGEX_OPTS)
212
+ DECADE_4CHAR_REGEX = Regexp.new('(^|\D)\d{3}[u\-?x]($|\D)', REGEX_OPTS)
199
213
 
200
214
  # first year of decade (as String) if we have: yyyu, yyy-, yyy? or yyyx pattern
201
215
  # note that these are the only decade patterns found in our actual date strings in MODS records
@@ -279,7 +293,7 @@ class ParseDate
279
293
  "-#{Regexp.last_match(:last)}".to_i if date_str.match(BETWEEN_Yn_AND_Yn_BC_REGEX)
280
294
  end
281
295
 
282
- EARLY_NUMERIC_REGEX = Regexp.new('^\-?\d{1,3}([^\du\-\[]|$)', REGEX_OPTS)
296
+ EARLY_NUMERIC_REGEX = Regexp.new('^\-?\d{1,3}([^\du\[]|$)', REGEX_OPTS)
283
297
 
284
298
  # year if date_str contains yyy, yy, y, -y, -yy, -yyy, -yyyy
285
299
  # @return [Integer, nil] year if date_str matches pattern; nil otherwise
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ParseDate
4
- VERSION = '0.3.1'
4
+ VERSION = '0.3.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse_date
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naomi Dushay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-22 00:00:00.000000000 Z
11
+ date: 2019-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk