parse_date 0.4.3 → 0.4.4

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: 60c444ed79ea6842f49bfb44d2adc5bd1a6790d483fe43e0bd4a0880001a6005
4
- data.tar.gz: a62f906a4c908c4b774ef9fe1dae2a047deee79ee6569688d1c2db9796bb3b2e
3
+ metadata.gz: f613d991c15686a1b4ba6306fe8f0260a1b0e6159b868cba4f6894be3369df2c
4
+ data.tar.gz: 6c39918199136340604ab472ecc8c3898a13b88aea1f2d2bbd19ea7090a5bfec
5
5
  SHA512:
6
- metadata.gz: a949b307fb3259f1a20fa279aa2af395137b514b35b15dbce8c63701047462b06b5b6cb31723f25dbef2c8f1db249cf8e95914d92c113dd4439ed6737267878f
7
- data.tar.gz: e1e3e154a6bc4851a7aafa199da3ee66e0d4b7d5d27537528cee36d2f0b2f80761fbbffffa1d2a544ca4a204f4fd7816f85a6d0b975824fff06cead4d64cf3f2
6
+ metadata.gz: 1dece18d4386a1701e57097c016dc8910eee7d9c447ae365ccdd27bea973fed67d377d154e42f5cb4c91bdc6c187a19c63d491f2ee7b8eeb30ac6fe62963ca91
7
+ data.tar.gz: 7e4b96fce7029cf4c1918c6cd6614d26e170e160ba72e94ee8fc8f1402a780000469c965249f8c69be30882161f93125aa44e592c0dbec4f49c7040a2c4a8ed3
@@ -0,0 +1,11 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby-rails: sul-dlss/ruby-rails@4.6.0
4
+ workflows:
5
+ build:
6
+ jobs:
7
+ - ruby-rails/lint-gem:
8
+ name: lint
9
+ - ruby-rails/test-gem:
10
+ name: test
11
+ context: dlss
data/.gitignore CHANGED
@@ -10,6 +10,5 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
 
13
- Gemfile.lock
14
13
 
15
14
  .pry_history
data/.rubocop.yml CHANGED
@@ -1,5 +1,24 @@
1
+ plugins:
2
+ - rubocop-capybara
3
+ - rubocop-factory_bot
4
+ - rubocop-rake
5
+ - rubocop-rspec
6
+ - rubocop-rspec_rails
7
+
1
8
  inherit_from: .rubocop_todo.yml
2
9
 
10
+ AllCops:
11
+ TargetRubyVersion: 3.1
12
+ SuggestExtensions: false
13
+ DisplayCopNames: true
14
+ Include:
15
+ - './Rakefile' # rake only
16
+ - '**/*.rb'
17
+ Exclude:
18
+ # autogenerated files (that we don't change) should go here
19
+ - 'bin/**/*'
20
+ - 'spec/spec_helper.rb'
21
+
3
22
  Gemspec/RequiredRubyVersion:
4
23
  Enabled: false
5
24
 
@@ -27,6 +46,12 @@ Metrics/ModuleLength:
27
46
  Exclude:
28
47
  - lib/parse_date/int_from_string.rb
29
48
 
49
+ RSpec/MultipleMemoizedHelpers:
50
+ Enabled: false
51
+
52
+ RSpec/NestedGroups:
53
+ Max: 4 # default: 3
54
+
30
55
  Style/Documentation:
31
56
  Exclude:
32
57
  - lib/parse_date.rb
@@ -48,8 +73,6 @@ Style/WordArray:
48
73
  Style/YodaCondition:
49
74
  Enabled: false
50
75
 
51
- Gemspec/DateAssignment: # (new in 1.10)
52
- Enabled: true
53
76
  Layout/SpaceBeforeBrackets: # (new in 1.7)
54
77
  Enabled: true
55
78
  Lint/AmbiguousAssignment: # (new in 1.7)
@@ -108,3 +131,283 @@ Style/StringChars: # (new in 1.12)
108
131
  Enabled: true
109
132
  Style/SwapValues: # (new in 1.1)
110
133
  Enabled: true
134
+ Gemspec/DeprecatedAttributeAssignment: # new in 1.30
135
+ Enabled: true
136
+ Gemspec/RequireMFA: # new in 1.23
137
+ Enabled: true
138
+ Layout/LineContinuationLeadingSpace: # new in 1.31
139
+ Enabled: true
140
+ Layout/LineContinuationSpacing: # new in 1.31
141
+ Enabled: true
142
+ Layout/LineEndStringConcatenationIndentation: # new in 1.18
143
+ Enabled: true
144
+ Lint/AmbiguousOperatorPrecedence: # new in 1.21
145
+ Enabled: true
146
+ Lint/AmbiguousRange: # new in 1.19
147
+ Enabled: true
148
+ Lint/ConstantOverwrittenInRescue: # new in 1.31
149
+ Enabled: true
150
+ Lint/EmptyInPattern: # new in 1.16
151
+ Enabled: true
152
+ Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
153
+ Enabled: true
154
+ Lint/NonAtomicFileOperation: # new in 1.31
155
+ Enabled: true
156
+ Lint/RefinementImportMethods: # new in 1.27
157
+ Enabled: true
158
+ Lint/RequireRelativeSelfPath: # new in 1.22
159
+ Enabled: true
160
+ Lint/UselessRuby2Keywords: # new in 1.23
161
+ Enabled: true
162
+ Naming/BlockForwarding: # new in 1.24
163
+ Enabled: true
164
+ Security/CompoundHash: # new in 1.28
165
+ Enabled: true
166
+ Security/IoMethods: # new in 1.22
167
+ Enabled: true
168
+ Style/EnvHome: # new in 1.29
169
+ Enabled: true
170
+ Style/FetchEnvVar: # new in 1.28
171
+ Enabled: true
172
+ Style/FileRead: # new in 1.24
173
+ Enabled: true
174
+ Style/FileWrite: # new in 1.24
175
+ Enabled: true
176
+ Style/InPatternThen: # new in 1.16
177
+ Enabled: true
178
+ Style/MapCompactWithConditionalBlock: # new in 1.30
179
+ Enabled: true
180
+ Style/MapToHash: # new in 1.24
181
+ Enabled: true
182
+ Style/MultilineInPatternThen: # new in 1.16
183
+ Enabled: true
184
+ Style/NestedFileDirname: # new in 1.26
185
+ Enabled: true
186
+ Style/NumberedParameters: # new in 1.22
187
+ Enabled: true
188
+ Style/NumberedParametersLimit: # new in 1.22
189
+ Enabled: true
190
+ Style/ObjectThen: # new in 1.28
191
+ Enabled: true
192
+ Style/OpenStructUse: # new in 1.23
193
+ Enabled: true
194
+ Style/QuotedSymbols: # new in 1.16
195
+ Enabled: true
196
+ Style/RedundantInitialize: # new in 1.27
197
+ Enabled: true
198
+ Style/RedundantSelfAssignmentBranch: # new in 1.19
199
+ Enabled: true
200
+ Style/SelectByRegexp: # new in 1.22
201
+ Enabled: true
202
+
203
+ Lint/RequireRangeParentheses: # new in 1.32
204
+ Enabled: true
205
+ Style/EmptyHeredoc: # new in 1.32
206
+ Enabled: true
207
+ Style/MagicCommentFormat: # new in 1.35
208
+ Enabled: true
209
+ RSpec/BeEq: # new in 2.9.0
210
+ Enabled: true
211
+ RSpec/BeNil: # new in 2.9.0
212
+ Enabled: true
213
+ RSpec/ChangeByZero: # new in 2.11
214
+ Enabled: true
215
+ RSpec/ClassCheck: # new in 2.13
216
+ Enabled: true
217
+ RSpec/ExcessiveDocstringSpacing: # new in 2.5
218
+ Enabled: true
219
+ RSpec/IdenticalEqualityAssertion: # new in 2.4
220
+ Enabled: true
221
+ RSpec/NoExpectationExample: # new in 2.13
222
+ Enabled: true
223
+ RSpec/SubjectDeclaration: # new in 2.5
224
+ Enabled: true
225
+ RSpec/VerifiedDoubleReference: # new in 2.10.0
226
+ Enabled: true
227
+ Capybara/SpecificFinders: # new in 2.13
228
+ Enabled: true
229
+ Capybara/SpecificMatcher: # new in 2.12
230
+ Enabled: true
231
+ FactoryBot/SyntaxMethods: # new in 2.7
232
+ Enabled: true
233
+ RSpecRails/AvoidSetupHook: # new in 2.4
234
+ Enabled: true
235
+ RSpecRails/HaveHttpStatus: # new in 2.12
236
+ Enabled: true
237
+
238
+ Gemspec/AddRuntimeDependency: # new in 1.65
239
+ Enabled: true
240
+ Gemspec/DevelopmentDependencies: # new in 1.44
241
+ Enabled: true
242
+ Lint/ArrayLiteralInRegexp: # new in 1.71
243
+ Enabled: true
244
+ Lint/ConstantReassignment: # new in 1.70
245
+ Enabled: true
246
+ Lint/CopDirectiveSyntax: # new in 1.72
247
+ Enabled: true
248
+ Lint/DuplicateMagicComment: # new in 1.37
249
+ Enabled: true
250
+ Lint/DuplicateMatchPattern: # new in 1.50
251
+ Enabled: true
252
+ Lint/DuplicateSetElement: # new in 1.67
253
+ Enabled: true
254
+ Lint/HashNewWithKeywordArgumentsAsDefault: # new in 1.69
255
+ Enabled: true
256
+ Lint/ItWithoutArgumentsInBlock: # new in 1.59
257
+ Enabled: true
258
+ Lint/LiteralAssignmentInCondition: # new in 1.58
259
+ Enabled: true
260
+ Lint/MixedCaseRange: # new in 1.53
261
+ Enabled: true
262
+ Lint/NumericOperationWithConstantResult: # new in 1.69
263
+ Enabled: true
264
+ Lint/RedundantRegexpQuantifiers: # new in 1.53
265
+ Enabled: true
266
+ Lint/RedundantTypeConversion: # new in 1.72
267
+ Enabled: true
268
+ Lint/SharedMutableDefault: # new in 1.70
269
+ Enabled: true
270
+ Lint/SuppressedExceptionInNumberConversion: # new in 1.72
271
+ Enabled: true
272
+ Lint/UnescapedBracketInRegexp: # new in 1.68
273
+ Enabled: true
274
+ Lint/UselessConstantScoping: # new in 1.72
275
+ Enabled: true
276
+ Exclude:
277
+ - lib/parse_date/int_from_string.rb
278
+ Lint/UselessDefined: # new in 1.69
279
+ Enabled: true
280
+ Lint/UselessNumericOperation: # new in 1.66
281
+ Enabled: true
282
+ Lint/UselessRescue: # new in 1.43
283
+ Enabled: true
284
+ Metrics/CollectionLiteralLength: # new in 1.47
285
+ Enabled: true
286
+ Style/AmbiguousEndlessMethodDefinition: # new in 1.68
287
+ Enabled: true
288
+ Style/ArrayIntersect: # new in 1.40
289
+ Enabled: true
290
+ Style/BitwisePredicate: # new in 1.68
291
+ Enabled: true
292
+ Style/CombinableDefined: # new in 1.68
293
+ Enabled: true
294
+ Style/ComparableBetween: # new in 1.74
295
+ Enabled: true
296
+ Style/ComparableClamp: # new in 1.44
297
+ Enabled: true
298
+ Style/ConcatArrayLiterals: # new in 1.41
299
+ Enabled: true
300
+ Style/DataInheritance: # new in 1.49
301
+ Enabled: true
302
+ Style/DigChain: # new in 1.69
303
+ Enabled: true
304
+ Style/DirEmpty: # new in 1.48
305
+ Enabled: true
306
+ Style/ExactRegexpMatch: # new in 1.51
307
+ Enabled: true
308
+ Style/FileEmpty: # new in 1.48
309
+ Enabled: true
310
+ Style/FileNull: # new in 1.69
311
+ Enabled: true
312
+ Style/FileTouch: # new in 1.69
313
+ Enabled: true
314
+ Style/HashFetchChain: # new in 1.75
315
+ Enabled: true
316
+ Style/HashSlice: # new in 1.71
317
+ Enabled: true
318
+ Style/ItAssignment: # new in 1.70
319
+ Enabled: true
320
+ Style/ItBlockParameter: # new in 1.75
321
+ Enabled: true
322
+ Style/KeywordArgumentsMerging: # new in 1.68
323
+ Enabled: true
324
+ Style/MapIntoArray: # new in 1.63
325
+ Enabled: true
326
+ Style/MapToSet: # new in 1.42
327
+ Enabled: true
328
+ Style/MinMaxComparison: # new in 1.42
329
+ Enabled: true
330
+ Style/OperatorMethodCall: # new in 1.37
331
+ Enabled: true
332
+ Style/RedundantArrayConstructor: # new in 1.52
333
+ Enabled: true
334
+ Style/RedundantConstantBase: # new in 1.40
335
+ Enabled: true
336
+ Style/RedundantCurrentDirectoryInPath: # new in 1.53
337
+ Enabled: true
338
+ Style/RedundantDoubleSplatHashBraces: # new in 1.41
339
+ Enabled: true
340
+ Style/RedundantEach: # new in 1.38
341
+ Enabled: true
342
+ Style/RedundantFilterChain: # new in 1.52
343
+ Enabled: true
344
+ Style/RedundantFormat: # new in 1.72
345
+ Enabled: true
346
+ Style/RedundantHeredocDelimiterQuotes: # new in 1.45
347
+ Enabled: true
348
+ Style/RedundantInterpolationUnfreeze: # new in 1.66
349
+ Enabled: true
350
+ Style/RedundantLineContinuation: # new in 1.49
351
+ Enabled: true
352
+ Style/RedundantRegexpArgument: # new in 1.53
353
+ Enabled: true
354
+ Style/RedundantRegexpConstructor: # new in 1.52
355
+ Enabled: true
356
+ Exclude:
357
+ - lib/parse_date/int_from_string.rb
358
+ Style/RedundantStringEscape: # new in 1.37
359
+ Enabled: true
360
+ Style/ReturnNilInPredicateMethodDefinition: # new in 1.53
361
+ Enabled: true
362
+ Style/SafeNavigationChainLength: # new in 1.68
363
+ Enabled: true
364
+ Style/SendWithLiteralMethodName: # new in 1.64
365
+ Enabled: true
366
+ Style/SingleLineDoEndBlock: # new in 1.57
367
+ Enabled: true
368
+ Style/SuperArguments: # new in 1.64
369
+ Enabled: true
370
+ Style/SuperWithArgsParentheses: # new in 1.58
371
+ Enabled: true
372
+ Style/YAMLFileRead: # new in 1.53
373
+ Enabled: true
374
+ Capybara/FindAllFirst: # new in 2.22
375
+ Enabled: true
376
+ Capybara/MatchStyle: # new in 2.17
377
+ Enabled: true
378
+ Capybara/NegationMatcher: # new in 2.14
379
+ Enabled: true
380
+ Capybara/NegationMatcherAfterVisit: # new in 2.22
381
+ Enabled: true
382
+ Capybara/RedundantWithinFind: # new in 2.20
383
+ Enabled: true
384
+ Capybara/SpecificActions: # new in 2.14
385
+ Enabled: true
386
+ Capybara/RSpec/HaveSelector: # new in 2.19
387
+ Enabled: true
388
+ Capybara/RSpec/PredicateMatcher: # new in 2.19
389
+ Enabled: true
390
+ FactoryBot/AssociationStyle: # new in 2.23
391
+ Enabled: true
392
+ FactoryBot/ConsistentParenthesesStyle: # new in 2.14
393
+ Enabled: true
394
+ FactoryBot/ExcessiveCreateList: # new in 2.25
395
+ Enabled: true
396
+ FactoryBot/FactoryAssociationWithStrategy: # new in 2.23
397
+ Enabled: true
398
+ FactoryBot/FactoryNameStyle: # new in 2.16
399
+ Enabled: true
400
+ FactoryBot/IdSequence: # new in 2.24
401
+ Enabled: true
402
+ FactoryBot/RedundantFactoryOption: # new in 2.23
403
+ Enabled: true
404
+ RSpec/IncludeExamples: # new in 3.6
405
+ Enabled: true
406
+ RSpecRails/InferredSpecType: # new in 2.14
407
+ Enabled: true
408
+ RSpecRails/MinitestAssertions: # new in 2.17
409
+ Enabled: true
410
+ RSpecRails/NegationBeValid: # new in 2.23
411
+ Enabled: true
412
+ RSpecRails/TravelAround: # new in 2.19
413
+ Enabled: true
data/.rubocop_todo.yml CHANGED
@@ -1,7 +1,25 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2021-03-26 19:20:09 UTC using RuboCop version 1.12.0.
3
+ # on 2022-10-07 22:01:55 UTC using RuboCop version 1.36.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
7
7
  # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 5
10
+ # This cop supports safe autocorrection (--autocorrect).
11
+ Lint/AmbiguousOperatorPrecedence:
12
+ Exclude:
13
+ - 'lib/parse_date/int_from_string.rb'
14
+
15
+ # Offense count: 11
16
+ RSpec/RepeatedDescription:
17
+ Exclude:
18
+ - 'spec/parse_date/int_from_string_spec.rb'
19
+ - 'spec/parse_date_spec.rb'
20
+
21
+ # Offense count: 14
22
+ RSpec/RepeatedExample:
23
+ Exclude:
24
+ - 'spec/parse_date/int_from_string_spec.rb'
25
+ - 'spec/parse_date_spec.rb'
data/Gemfile.lock ADDED
@@ -0,0 +1,123 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ parse_date (0.4.4)
5
+ zeitwerk (~> 2.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.3)
11
+ date (3.4.1)
12
+ debug (1.11.0)
13
+ irb (~> 1.10)
14
+ reline (>= 0.3.8)
15
+ diff-lcs (1.6.2)
16
+ docile (1.4.1)
17
+ erb (5.0.2)
18
+ io-console (0.8.1)
19
+ irb (1.15.2)
20
+ pp (>= 0.6.0)
21
+ rdoc (>= 4.0.0)
22
+ reline (>= 0.4.2)
23
+ json (2.13.2)
24
+ language_server-protocol (3.17.0.5)
25
+ lint_roller (1.1.0)
26
+ parallel (1.27.0)
27
+ parser (3.3.9.0)
28
+ ast (~> 2.4.1)
29
+ racc
30
+ pp (0.6.2)
31
+ prettyprint
32
+ prettyprint (0.2.0)
33
+ prism (1.5.1)
34
+ psych (5.2.6)
35
+ date
36
+ stringio
37
+ racc (1.8.1)
38
+ rainbow (3.1.1)
39
+ rake (13.0.6)
40
+ rdoc (6.14.2)
41
+ erb
42
+ psych (>= 4.0.0)
43
+ regexp_parser (2.11.3)
44
+ reline (0.6.2)
45
+ io-console (~> 0.5)
46
+ rspec (3.13.1)
47
+ rspec-core (~> 3.13.0)
48
+ rspec-expectations (~> 3.13.0)
49
+ rspec-mocks (~> 3.13.0)
50
+ rspec-core (3.13.5)
51
+ rspec-support (~> 3.13.0)
52
+ rspec-expectations (3.13.5)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.13.0)
55
+ rspec-mocks (3.13.5)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.13.0)
58
+ rspec-support (3.13.5)
59
+ rubocop (1.80.2)
60
+ json (~> 2.3)
61
+ language_server-protocol (~> 3.17.0.2)
62
+ lint_roller (~> 1.1.0)
63
+ parallel (~> 1.10)
64
+ parser (>= 3.3.0.2)
65
+ rainbow (>= 2.2.2, < 4.0)
66
+ regexp_parser (>= 2.9.3, < 3.0)
67
+ rubocop-ast (>= 1.46.0, < 2.0)
68
+ ruby-progressbar (~> 1.7)
69
+ unicode-display_width (>= 2.4.0, < 4.0)
70
+ rubocop-ast (1.46.0)
71
+ parser (>= 3.3.7.2)
72
+ prism (~> 1.4)
73
+ rubocop-capybara (2.22.1)
74
+ lint_roller (~> 1.1)
75
+ rubocop (~> 1.72, >= 1.72.1)
76
+ rubocop-factory_bot (2.27.1)
77
+ lint_roller (~> 1.1)
78
+ rubocop (~> 1.72, >= 1.72.1)
79
+ rubocop-rake (0.7.1)
80
+ lint_roller (~> 1.1)
81
+ rubocop (>= 1.72.1)
82
+ rubocop-rspec (3.7.0)
83
+ lint_roller (~> 1.1)
84
+ rubocop (~> 1.72, >= 1.72.1)
85
+ rubocop-rspec_rails (2.31.0)
86
+ lint_roller (~> 1.1)
87
+ rubocop (~> 1.72, >= 1.72.1)
88
+ rubocop-rspec (~> 3.5)
89
+ ruby-progressbar (1.13.0)
90
+ simplecov (0.22.0)
91
+ docile (~> 1.1)
92
+ simplecov-html (~> 0.11)
93
+ simplecov_json_formatter (~> 0.1)
94
+ simplecov-html (0.13.2)
95
+ simplecov_json_formatter (0.1.4)
96
+ stringio (3.1.7)
97
+ unicode-display_width (3.2.0)
98
+ unicode-emoji (~> 4.1)
99
+ unicode-emoji (4.1.0)
100
+ zeitwerk (2.7.3)
101
+
102
+ PLATFORMS
103
+ arm64-darwin-24
104
+ x86_64-darwin-19
105
+ x86_64-darwin-22
106
+ x86_64-linux
107
+
108
+ DEPENDENCIES
109
+ bundler (~> 2.0)
110
+ debug
111
+ parse_date!
112
+ rake (~> 13.0.3)
113
+ rspec (~> 3.0)
114
+ rubocop (~> 1.12)
115
+ rubocop-capybara
116
+ rubocop-factory_bot
117
+ rubocop-rake
118
+ rubocop-rspec
119
+ rubocop-rspec_rails
120
+ simplecov
121
+
122
+ BUNDLED WITH
123
+ 2.7.2
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/parse_date.svg)](https://badge.fury.io/rb/parse_date)
2
- [![Build Status](https://travis-ci.com/sul-dlss/parse_date.svg?branch=main)](https://travis-ci.com/sul-dlss/parse_date)
3
- [![Maintainability](https://api.codeclimate.com/v1/badges/2d006b4ccb3100434f4a/maintainability)](https://codeclimate.com/github/sul-dlss/parse_date/maintainability)
4
- [![Test Coverage](https://api.codeclimate.com/v1/badges/2d006b4ccb3100434f4a/test_coverage)](https://codeclimate.com/github/sul-dlss/parse_date/test_coverage)
2
+ [![CircleCI](https://dl.circleci.com/status-badge/img/gh/sul-dlss/parse_date/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/sul-dlss/parse_date/tree/main)
3
+ [![codecov](https://codecov.io/github/sul-dlss/parse_date/graph/badge.svg?token=SLX8J6L6ZV)](https://codecov.io/github/sul-dlss/parse_date)
5
4
 
6
5
  # ParseDate
7
6
 
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ParseDate
4
-
5
4
  # Parse (Year) Integers from Date Strings
6
5
  module IntFromString
7
-
8
6
  # earliest year as Integer if we can parse one from date_str
9
7
  # e.g. if 17uu, result is 1700
10
8
  # NOTE: if we have a x/x/yy or x-x-yy pattern (the only 2 digit year patterns
@@ -13,19 +11,19 @@ class ParseDate
13
11
  # 1/1/17 -> 2017
14
12
  # 1/1/27 -> 1927
15
13
  # @return [Integer, nil] Integer year if we could parse one, nil otherwise
16
- def self.earliest_year(date_str)
14
+ def earliest_year(date_str)
17
15
  return unless date_str && !date_str.empty?
18
16
  return if date_str == '0000-00-00' # shpc collection has these useless dates
19
17
 
20
18
  # B.C. first (match longest string first)
21
- bc_result = ParseDate.send(:earliest_year_bc_parsing, date_str)
19
+ bc_result = earliest_year_bc_parsing(date_str)
22
20
  return bc_result if bc_result
23
21
 
24
- result = ParseDate.send(:earliest_year_parsing, date_str)
22
+ result = earliest_year_parsing(date_str)
25
23
  return result if result
26
24
 
27
25
  # try removing brackets between digits in case we have 169[5] or [18]91
28
- no_brackets = ParseDate.send(:remove_brackets, date_str)
26
+ no_brackets = remove_brackets(date_str)
29
27
  earliest_year(no_brackets) if no_brackets
30
28
  end
31
29
 
@@ -37,40 +35,43 @@ class ParseDate
37
35
  # 1/1/17 -> 2017
38
36
  # 1/1/27 -> 1927
39
37
  # @return [Integer, nil] Integer year if we could parse one, nil otherwise
40
- def self.latest_year(date_str)
38
+ def latest_year(date_str)
41
39
  return unless date_str && !date_str.empty?
42
40
  return if date_str == '0000-00-00' # shpc collection has these useless dates
43
41
 
44
42
  # B.C. first (match longest string first)
45
- bc_result = ParseDate.send(:latest_year_bc_parsing, date_str)
43
+ bc_result = latest_year_bc_parsing(date_str)
46
44
  return bc_result if bc_result
47
45
 
48
- result = ParseDate.send(:latest_year_parsing, date_str)
46
+ result = latest_year_parsing(date_str)
49
47
  return result if result
50
48
 
51
49
  # try removing brackets between digits in case we have 169[5] or [18]91
52
- no_brackets = ParseDate.send(:remove_brackets, date_str)
50
+ no_brackets = remove_brackets(date_str)
53
51
  latest_year(no_brackets) if no_brackets
54
52
  end
55
53
 
56
54
  # true if the year is between -9999 and (current year + 1), inclusive
57
55
  # @return [Boolean] true if the year is between -999 and (current year + 1); false otherwise
58
- def self.year_int_valid?(year)
56
+ def year_int_valid?(year)
59
57
  return false unless year.is_a? Integer
60
58
 
61
59
  (-10000 < year.to_i) && (year < Date.today.year + 2)
62
60
  end
63
61
 
64
- protected
62
+ private
65
63
 
66
64
  def earliest_year_bc_parsing(date_str)
67
- return ParseDate.send(:earliest_century_bc, date_str) if date_str.match(YY_YY_CENTURY_BC_REGEX)
68
- return ParseDate.send(:between_bc_earliest_year, date_str) if date_str.match(BETWEEN_Yn_AND_Yn_BC_REGEX)
69
- return ParseDate.send(:year_int_for_bc, date_str) if date_str.match(YEAR_BC_REGEX)
65
+ return earliest_century_bc(date_str) if date_str.match(YY_YY_CENTURY_BC_REGEX)
66
+ return between_bc_earliest_year(date_str) if date_str.match(BETWEEN_Yn_AND_Yn_BC_REGEX)
67
+
68
+ year_int_for_bc(date_str) if date_str.match(YEAR_BC_REGEX)
70
69
  end
71
70
 
72
71
  def earliest_year_parsing(date_str)
73
72
  [
73
+ # DataWorks date ranges include slashes and hyphens that match date_str/date_str
74
+ :slash_earliest_year,
74
75
  # longest string first, more or less
75
76
  :between_earliest_year,
76
77
  :hyphen_4digit_earliest_year,
@@ -81,23 +82,26 @@ class ParseDate
81
82
  :first_year_for_century, # includes some BC
82
83
  :year_for_early_numeric
83
84
  ].each do |method_name|
84
- result = ParseDate.send(method_name, date_str)
85
+ result = send(method_name, date_str)
85
86
  return result.to_i if result && year_int_valid?(result.to_i)
86
87
  end
87
88
  nil
88
89
  end
89
90
 
90
91
  def latest_year_bc_parsing(date_str)
91
- return ParseDate.send(:last_year_mult_centuries_bc, date_str) if date_str.match(YY_YY_CENTURY_BC_REGEX)
92
- return ParseDate.send(:between_bc_latest_year, date_str) if date_str.match(BETWEEN_Yn_AND_Yn_BC_REGEX)
93
- return ParseDate.send(:last_year_for_bc_century, date_str) if date_str.match(BC_CENTURY_REGEX)
94
- return ParseDate.send(:year_int_for_bc, date_str) if date_str.match(BC_REGEX)
92
+ return last_year_mult_centuries_bc(date_str) if date_str.match(YY_YY_CENTURY_BC_REGEX)
93
+ return between_bc_latest_year(date_str) if date_str.match(BETWEEN_Yn_AND_Yn_BC_REGEX)
94
+ return last_year_for_bc_century(date_str) if date_str.match(BC_CENTURY_REGEX)
95
+
96
+ year_int_for_bc(date_str) if date_str.match(BC_REGEX)
95
97
  end
96
98
 
97
99
  # rubocop:disable Metrics/MethodLength
98
100
  def latest_year_parsing(date_str)
99
101
  result = nil
100
102
  [
103
+ # DataWorks date ranges include slashes and hyphens that match date_str/date_str
104
+ :slash_latest_year,
101
105
  # longest string first, more or less
102
106
  :between_latest_year,
103
107
  :hyphen_4digit_latest_year,
@@ -115,7 +119,7 @@ class ParseDate
115
119
  :last_year_for_century,
116
120
  :last_year_for_early_numeric
117
121
  ].each do |method|
118
- result ||= ParseDate.send(method, date_str)
122
+ result ||= send(method, date_str)
119
123
  return result.to_i if result && year_int_valid?(result.to_i)
120
124
  end
121
125
  nil
@@ -143,8 +147,8 @@ class ParseDate
143
147
  # @return [Integer, nil] yyyy if date_str matches pattern; nil otherwise
144
148
  def hyphen_4digit_latest_year(date_str)
145
149
  latest = Regexp.last_match(:last) if date_str.match(YYYY_HYPHEN_YYYY_REGEX)
146
- if ParseDate.year_int_valid?(latest.to_i)
147
- ParseDate.latest_year(latest) # accommodates '1980s - 1990s'
150
+ if year_int_valid?(latest.to_i)
151
+ latest_year(latest) # accommodates '1980s - 1990s'
148
152
  else
149
153
  # return the bad value; parse_range might need to complain about it
150
154
  latest
@@ -162,7 +166,7 @@ class ParseDate
162
166
  first = Regexp.last_match(:first)
163
167
  century = first[0..-3] # whatever is before the last 2 digits
164
168
  last = "#{century}#{Regexp.last_match(:last)}"
165
- last.to_i if ParseDate.year_range_valid?(first.to_i, last.to_i)
169
+ last.to_i if year_range_valid?(first.to_i, last.to_i)
166
170
  end
167
171
 
168
172
  YYYY_HYPHEN_Y_REGEX = Regexp.new(/(?<first>\d{3,4})\??\s*(-|—|–|to)\s*(?<last>\d{1})\??([^-0-9].*)?$/)
@@ -176,7 +180,7 @@ class ParseDate
176
180
  first = Regexp.last_match(:first)
177
181
  decade = first[0..-2] # whatever is before the last digit
178
182
  last = "#{decade}#{Regexp.last_match(:last)}"
179
- last.to_i if ParseDate.year_range_valid?(first.to_i, last.to_i)
183
+ last.to_i if year_range_valid?(first.to_i, last.to_i)
180
184
  end
181
185
 
182
186
  YYUU = '\\d{1,2}[u\\-]{2}'
@@ -279,7 +283,7 @@ class ParseDate
279
283
  def last_year_for_0s_decade(date_str)
280
284
  decade_matches = date_str.match(DECADE_0S_REGEX)
281
285
  changed_to_nine = decade_matches.to_s.sub(/0'?s/, '9') if decade_matches
282
- ParseDate.first_four_digits(changed_to_nine) if changed_to_nine
286
+ first_four_digits(changed_to_nine) if changed_to_nine
283
287
  end
284
288
 
285
289
  DECADE_4CHAR_REGEX = Regexp.new('(^|\D)\d{3}[u\-?x]($|\D)', REGEX_OPTS)
@@ -290,7 +294,7 @@ class ParseDate
290
294
  def first_year_for_decade(date_str)
291
295
  decade_matches = date_str.match(DECADE_4CHAR_REGEX)
292
296
  changed_to_zero = decade_matches.to_s.tr('u\-?x', '0') if decade_matches
293
- ParseDate.first_four_digits(changed_to_zero) if changed_to_zero
297
+ first_four_digits(changed_to_zero) if changed_to_zero
294
298
  end
295
299
 
296
300
  # last year of decade (as String) if we have: yyyu, yyy-, yyy? or yyyx pattern
@@ -299,7 +303,7 @@ class ParseDate
299
303
  def last_year_for_decade(date_str)
300
304
  decade_matches = date_str.match(DECADE_4CHAR_REGEX)
301
305
  changed_to_nine = decade_matches.to_s.tr('u\-?x', '9') if decade_matches
302
- ParseDate.first_four_digits(changed_to_nine) if changed_to_nine
306
+ first_four_digits(changed_to_nine) if changed_to_nine
303
307
  end
304
308
 
305
309
  CENTURY_WORD_REGEX = Regexp.new('(\d{1,2})[a-z]{2}?\s*century', REGEX_OPTS)
@@ -313,7 +317,8 @@ class ParseDate
313
317
  return Regexp.last_match(1).to_i * -100 - 99 if date_str.match(BC_CENTURY_REGEX)
314
318
  return Regexp.last_match(1).to_i * 100 if date_str.match(CENTURY_4CHAR_REGEX)
315
319
  return (Regexp.last_match(:first).to_i - 1) * 100 if date_str.match(YY_YY_CENTURY_REGEX)
316
- return (Regexp.last_match(1).to_i - 1) * 100 if date_str.match(CENTURY_WORD_REGEX)
320
+
321
+ (Regexp.last_match(1).to_i - 1) * 100 if date_str.match(CENTURY_WORD_REGEX)
317
322
  end
318
323
  # rubocop:enable Metrics/AbcSize
319
324
 
@@ -321,7 +326,8 @@ class ParseDate
321
326
  # @return [Integer, nil] yy99 if date_str matches pattern, nil otherwise; also nil if B.C. in pattern
322
327
  def last_year_for_century(date_str)
323
328
  return Regexp.last_match(1).to_i * 100 + 99 if date_str.match(CENTURY_4CHAR_REGEX)
324
- return (Regexp.last_match(1).to_i - 1) * 100 + 99 if date_str.match(CENTURY_WORD_REGEX)
329
+
330
+ (Regexp.last_match(1).to_i - 1) * 100 + 99 if date_str.match(CENTURY_WORD_REGEX)
325
331
  end
326
332
 
327
333
  # last year of century (as String) if we have: nth century BC
@@ -330,6 +336,21 @@ class ParseDate
330
336
  Regexp.last_match(1).to_i * -100 if date_str.match(BC_CENTURY_REGEX)
331
337
  end
332
338
 
339
+ # Regex for a date range pattern with a slash: 2023-01-02T19:20:30+01:00/2025-01-01
340
+ DATESTR_REGEX = Regexp.new(/\b(\d{4})\b.*?\/.*?\b(\d{4})\b/im) # rubocop:disable Style/RegexpLiteral
341
+
342
+ # Integer value for earliest if we have "date_str/date_str" pattern
343
+ # @return [Integer, nil] year if date_str matches pattern; nil otherwise
344
+ def slash_earliest_year(date_str)
345
+ Regexp.last_match(1).to_i if date_str.match(DATESTR_REGEX)
346
+ end
347
+
348
+ # Integer value for latest if we have "date_str/date_str" pattern
349
+ # @return [Integer, nil] year if date_str matches pattern; nil otherwise
350
+ def slash_latest_year(date_str)
351
+ Regexp.last_match(2).to_i if date_str.match(DATESTR_REGEX)
352
+ end
353
+
333
354
  BETWEEN_Yn_AND_Yn_REGEX = Regexp.new(/between\s+(?<first>\d{1,4})\??\s+and\s+(?<last>\d{1,4})\??/im)
334
355
 
335
356
  # Integer value for earliest if we have "between y and y" pattern
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ParseDate
4
- VERSION = '0.4.3'
4
+ VERSION = '0.4.4'
5
5
  end
data/lib/parse_date.rb CHANGED
@@ -23,31 +23,18 @@ class ParseDate
23
23
  class Error < StandardError; end
24
24
 
25
25
  include Singleton
26
- extend ParseDate::IntFromString
27
-
28
- # class method delegation
29
- def self.earliest_year(date_str)
30
- ParseDate::IntFromString.earliest_year(date_str)
31
- end
32
-
33
- def self.latest_year(date_str)
34
- ParseDate::IntFromString.latest_year(date_str)
35
- end
36
-
37
- def self.year_int_valid?(date_str)
38
- ParseDate::IntFromString.year_int_valid?(date_str)
39
- end
26
+ extend IntFromString
40
27
 
41
28
  # @return [Array] array of Integer year values from earliest year to latest year, inclusive
42
29
  def self.parse_range(date_str)
43
30
  first = earliest_year(date_str)
44
31
  last = latest_year(date_str)
45
32
  return nil unless first || last
46
- raise ParseDate::Error, "Unable to parse range from '#{date_str}'" unless year_range_valid?(first, last)
33
+ raise Error, "Unable to parse range from '#{date_str}'" unless year_range_valid?(first, last)
47
34
 
48
35
  range_array(first, last)
49
36
  rescue StandardError => e
50
- raise ParseDate::Error, "Unable to parse range from '#{date_str}': #{e.message}"
37
+ raise Error, "Unable to parse range from '#{date_str}': #{e.message}"
51
38
  end
52
39
 
53
40
  # true if:
@@ -65,20 +52,16 @@ class ParseDate
65
52
  # @param [Integer, String] first_year, expecting integer or parseable string for .to_i
66
53
  # @param [Integer, String] last_year, expecting integer or parseable string for .to_i
67
54
  # @return [Array] array of Integer year values from first to last, inclusive
68
- # rubocop:disable Metrics/CyclomaticComplexity
69
- # rubocop:disable Metrics/PerceivedComplexity
70
- def self.range_array(first_year, last_year)
55
+ def self.range_array(first_year, last_year) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
71
56
  first_year = first_year.to_i if first_year.is_a?(String) && first_year.match?(/^-?\d+$/)
72
57
  last_year = last_year.to_i if last_year.is_a?(String) && last_year.match?(/^-?\d+$/)
73
58
 
74
59
  return [] unless last_year || first_year
75
60
  return [first_year] if last_year.nil? && first_year
76
61
  return [last_year] if first_year.nil? && last_year
77
- raise(ParseDate::Error, "unable to create year range array from #{first_year}, #{last_year}") unless
62
+ raise(Error, "unable to create year range array from #{first_year}, #{last_year}") unless
78
63
  year_range_valid?(first_year, last_year)
79
64
 
80
65
  Range.new(first_year, last_year).to_a
81
66
  end
82
- # rubocop:enable Metrics/CyclomaticComplexity
83
- # rubocop:enable Metrics/PerceivedComplexity
84
67
  end
data/parse_date.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = 'https://github.com/sul-dlss/parse_date'
16
16
 
17
17
  spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
18
-
18
+ spec.metadata['rubygems_mfa_required'] = 'true'
19
19
  spec.metadata['homepage_uri'] = spec.homepage
20
20
  spec.metadata['source_code_uri'] = 'https://github.com/sul-dlss/parse_date'
21
21
 
@@ -31,10 +31,14 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency 'zeitwerk', '~> 2.1'
32
32
 
33
33
  spec.add_development_dependency 'bundler', '~> 2.0'
34
- spec.add_development_dependency 'pry-byebug'
34
+ spec.add_development_dependency 'debug'
35
35
  spec.add_development_dependency 'rake', '~> 13.0.3'
36
36
  spec.add_development_dependency 'rspec', '~> 3.0'
37
37
  spec.add_development_dependency 'rubocop', '~> 1.12'
38
+ spec.add_development_dependency 'rubocop-capybara'
39
+ spec.add_development_dependency 'rubocop-factory_bot'
40
+ spec.add_development_dependency 'rubocop-rake'
38
41
  spec.add_development_dependency 'rubocop-rspec'
39
- spec.add_development_dependency 'simplecov', '~> 0.17.1' # CodeClimate cannot use SimpleCov >= 0.18.0 for generating test coverage
42
+ spec.add_development_dependency 'rubocop-rspec_rails'
43
+ spec.add_development_dependency 'simplecov'
40
44
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse_date
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naomi Dushay
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2021-03-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: zeitwerk
@@ -39,7 +38,7 @@ dependencies:
39
38
  - !ruby/object:Gem::Version
40
39
  version: '2.0'
41
40
  - !ruby/object:Gem::Dependency
42
- name: pry-byebug
41
+ name: debug
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - ">="
@@ -94,6 +93,48 @@ dependencies:
94
93
  - - "~>"
95
94
  - !ruby/object:Gem::Version
96
95
  version: '1.12'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rubocop-capybara
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rubocop-factory_bot
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ - !ruby/object:Gem::Dependency
125
+ name: rubocop-rake
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
97
138
  - !ruby/object:Gem::Dependency
98
139
  name: rubocop-rspec
99
140
  requirement: !ruby/object:Gem::Requirement
@@ -108,20 +149,34 @@ dependencies:
108
149
  - - ">="
109
150
  - !ruby/object:Gem::Version
110
151
  version: '0'
152
+ - !ruby/object:Gem::Dependency
153
+ name: rubocop-rspec_rails
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
111
166
  - !ruby/object:Gem::Dependency
112
167
  name: simplecov
113
168
  requirement: !ruby/object:Gem::Requirement
114
169
  requirements:
115
- - - "~>"
170
+ - - ">="
116
171
  - !ruby/object:Gem::Version
117
- version: 0.17.1
172
+ version: '0'
118
173
  type: :development
119
174
  prerelease: false
120
175
  version_requirements: !ruby/object:Gem::Requirement
121
176
  requirements:
122
- - - "~>"
177
+ - - ">="
123
178
  - !ruby/object:Gem::Version
124
- version: 0.17.1
179
+ version: '0'
125
180
  description: Get normalized date values for searching, faceting and display (e.g.
126
181
  in Solr search engine)
127
182
  email:
@@ -130,13 +185,14 @@ executables: []
130
185
  extensions: []
131
186
  extra_rdoc_files: []
132
187
  files:
188
+ - ".circleci/config.yml"
133
189
  - ".github/pull_request_template.md"
134
190
  - ".gitignore"
135
191
  - ".rspec"
136
192
  - ".rubocop.yml"
137
193
  - ".rubocop_todo.yml"
138
- - ".travis.yml"
139
194
  - Gemfile
195
+ - Gemfile.lock
140
196
  - LICENSE
141
197
  - README.md
142
198
  - Rakefile
@@ -150,9 +206,9 @@ homepage: https://github.com/sul-dlss/parse_date
150
206
  licenses: []
151
207
  metadata:
152
208
  allowed_push_host: https://rubygems.org/
209
+ rubygems_mfa_required: 'true'
153
210
  homepage_uri: https://github.com/sul-dlss/parse_date
154
211
  source_code_uri: https://github.com/sul-dlss/parse_date
155
- post_install_message:
156
212
  rdoc_options: []
157
213
  require_paths:
158
214
  - lib
@@ -167,8 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
223
  - !ruby/object:Gem::Version
168
224
  version: '0'
169
225
  requirements: []
170
- rubygems_version: 3.2.3
171
- signing_key:
226
+ rubygems_version: 3.7.0
172
227
  specification_version: 4
173
228
  summary: parse date values out of strings and normalize them
174
229
  test_files: []
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- dist: bionic
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.5.3
7
- - 2.6.4
8
-
9
- env:
10
- - 'RAILS_VERSION=5.2.3'
11
- - 'RAILS_VERSION=6.0.0'
12
-
13
- before_install: gem install bundler -v 2.0.2
14
-
15
- before_script:
16
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
17
- - chmod +x ./cc-test-reporter
18
- - ./cc-test-reporter before-build
19
- after_script:
20
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
21
-
22
- notifications:
23
- email: false