parse_date 0.4.1 → 0.4.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 +4 -4
- data/.rubocop.yml +8 -1
- data/.rubocop_todo.yml +2 -7
- data/README.md +4 -0
- data/lib/parse_date.rb +1 -1
- data/lib/parse_date/int_from_string.rb +16 -1
- data/lib/parse_date/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 184d14ddbda19e12229fd0b245505ee8a0891593bade0e99ca44d51603b3fa90
|
4
|
+
data.tar.gz: 293f5d385495c6fca24b94445d22a9680affa2a4cd50cf47b19733a12b612656
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8aca40d9e0ad5ccab88e589120a6009a4116026e6501974eb63bf13e7be018677ba581352b84d72f1ea288fbb8fd120a7717a85ce40770e289b97dbf695940e
|
7
|
+
data.tar.gz: e7c14cf9101f297982104c4aa5fe23597ee3932134770cd829ca38c67f4118b1c280962719a01f9f30dc917e01f9c076b7a909f157633cce842466218a9dd2b6
|
data/.rubocop.yml
CHANGED
@@ -17,7 +17,14 @@ Metrics/LineLength:
|
|
17
17
|
Max: 120
|
18
18
|
|
19
19
|
Metrics/MethodLength:
|
20
|
-
Max:
|
20
|
+
Max: 15
|
21
|
+
ExcludedMethods:
|
22
|
+
- earliest_year
|
23
|
+
- latest_year
|
24
|
+
|
25
|
+
Metrics/ModuleLength:
|
26
|
+
Exclude:
|
27
|
+
- lib/parse_date/int_from_string.rb
|
21
28
|
|
22
29
|
Style/NumericLiterals:
|
23
30
|
Enabled: false
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2019-11-
|
3
|
+
# on 2019-11-06 14:49:31 -0800 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,17 +8,12 @@
|
|
8
8
|
|
9
9
|
# Offense count: 5
|
10
10
|
Metrics/AbcSize:
|
11
|
-
Max:
|
11
|
+
Max: 45
|
12
12
|
|
13
13
|
# Offense count: 4
|
14
14
|
Metrics/CyclomaticComplexity:
|
15
15
|
Max: 12
|
16
16
|
|
17
|
-
# Offense count: 1
|
18
|
-
# Configuration parameters: CountComments.
|
19
|
-
Metrics/ModuleLength:
|
20
|
-
Max: 195
|
21
|
-
|
22
17
|
# Offense count: 4
|
23
18
|
Metrics/PerceivedComplexity:
|
24
19
|
Max: 12
|
data/README.md
CHANGED
@@ -46,6 +46,8 @@ ParseDate.parse_range('ca. 1930s') # (1930..1939).to_a
|
|
46
46
|
ParseDate.parse_range('1928-1980s') # (1928..1989).to_a
|
47
47
|
ParseDate.parse_range('1940s-1990') # (1940..1990).to_a
|
48
48
|
ParseDate.parse_range('1980s-1990s') # (1980..1999).to_a
|
49
|
+
ParseDate.parse_range('1675-7') # [1675, 1676, 1677]
|
50
|
+
ParseDate.parse_range('1040–1 CE') # [1040, 1041]
|
49
51
|
ParseDate.parse_range('18th century CE') # (1700..1799).to_a
|
50
52
|
ParseDate.parse_range('17uu') # (1700..1799).to_a
|
51
53
|
ParseDate.parse_range('between 1694 and 1799') # (1694..1799).to_a
|
@@ -124,6 +126,8 @@ ParseDate.latest_year('ca. 1930s') # 1939
|
|
124
126
|
ParseDate.latest_year('1928-1980s') # 1989
|
125
127
|
ParseDate.latest_year('1940s-1990') # 1990
|
126
128
|
ParseDate.latest_year('1980s-1990s') # 1999
|
129
|
+
ParseDate.latest_year('1675-7') # 1677
|
130
|
+
ParseDate.latest_year('1040–1 CE') # 1041
|
127
131
|
ParseDate.latest_year('18th century CE') # 1799
|
128
132
|
ParseDate.latest_year('17uu') # 1799
|
129
133
|
ParseDate.latest_year('between 1694 and 1799') # 1799
|
data/lib/parse_date.rb
CHANGED
@@ -72,7 +72,7 @@ class ParseDate
|
|
72
72
|
return [] unless last_year || first_year
|
73
73
|
return [first_year] if last_year.nil? && first_year
|
74
74
|
return [last_year] if first_year.nil? && last_year
|
75
|
-
raise(
|
75
|
+
raise(ParseDate::Error, "unable to create year range array from #{first_year}, #{last_year}") unless
|
76
76
|
year_range_valid?(first_year, last_year)
|
77
77
|
|
78
78
|
Range.new(first_year, last_year).to_a
|
@@ -61,6 +61,7 @@ class ParseDate
|
|
61
61
|
result ||= ParseDate.send(:between_latest_year, date_str)
|
62
62
|
result ||= ParseDate.send(:hyphen_4digit_latest_year, date_str)
|
63
63
|
result ||= ParseDate.send(:hyphen_2digit_latest_year, date_str)
|
64
|
+
result ||= ParseDate.send(:hyphen_1digit_latest_year, date_str)
|
64
65
|
result ||= ParseDate.send(:yyuu_after_hyphen, date_str)
|
65
66
|
result ||= ParseDate.send(:year_after_or, date_str)
|
66
67
|
result ||= ParseDate.send(:negative_4digits_after_hyphen, date_str)
|
@@ -75,7 +76,7 @@ class ParseDate
|
|
75
76
|
unless result
|
76
77
|
# try removing brackets between digits in case we have 169[5] or [18]91
|
77
78
|
no_brackets = ParseDate.send(:remove_brackets, date_str)
|
78
|
-
return
|
79
|
+
return latest_year(no_brackets) if no_brackets
|
79
80
|
end
|
80
81
|
result.to_i if result && year_int_valid?(result.to_i)
|
81
82
|
end
|
@@ -133,6 +134,20 @@ class ParseDate
|
|
133
134
|
last.to_i if ParseDate.year_range_valid?(first.to_i, last.to_i)
|
134
135
|
end
|
135
136
|
|
137
|
+
YYYY_HYPHEN_Y_REGEX = Regexp.new(/(?<first>\d{3,4})\??\s*(-|—|–|to)\s*(?<last>\d{1})\??([^-0-9].*)?$/)
|
138
|
+
|
139
|
+
# Integer value for latest year if we have "yyyy-y" pattern
|
140
|
+
# @return [Integer, nil] yyyy if date_str matches pattern; nil otherwise
|
141
|
+
def hyphen_1digit_latest_year(date_str)
|
142
|
+
matches = date_str.match(YYYY_HYPHEN_Y_REGEX)
|
143
|
+
return unless matches
|
144
|
+
|
145
|
+
first = Regexp.last_match(:first)
|
146
|
+
decade = first[0..-2] # whatever is before the last digit
|
147
|
+
last = "#{decade}#{Regexp.last_match(:last)}"
|
148
|
+
last.to_i if ParseDate.year_range_valid?(first.to_i, last.to_i)
|
149
|
+
end
|
150
|
+
|
136
151
|
YYUU = '\\d{1,2}[u\\-]{2}'
|
137
152
|
YYuu_HYPHEN_YYuu_REGEX =
|
138
153
|
Regexp.new("(?<first>#{YYUU})\\??\\s*(-|—|–|to)\\s*(?<last>#{YYUU})\\??([^u\\-]|$)??", REGEX_OPTS)
|
data/lib/parse_date/version.rb
CHANGED