Skip to content

Commit

Permalink
Merge 9e75242 into b5436f3
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 15, 2018
2 parents b5436f3 + 9e75242 commit ea87088
Show file tree
Hide file tree
Showing 19 changed files with 140 additions and 32 deletions.
72 changes: 49 additions & 23 deletions .rubocop_todo.yml
@@ -1,14 +1,14 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-08-08 21:42:13 -0700 using RuboCop version 0.57.1.
# on 2018-11-14 11:35:35 -0800 using RuboCop version 0.60.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Include, TreatCommentsAsGroupSeparators.
# Configuration parameters: TreatCommentsAsGroupSeparators, Include.
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
Bundler/OrderedGems:
Exclude:
Expand All @@ -22,7 +22,7 @@ Layout/AccessModifierIndentation:
Exclude:
- 'lib/stanford-mods/origin_info.rb'

# Offense count: 27
# Offense count: 22
# Cop supports --auto-correct.
Layout/AlignArray:
Exclude:
Expand All @@ -47,7 +47,7 @@ Layout/BlockEndNewline:
Exclude:
- 'spec/name_spec.rb'

# Offense count: 20
# Offense count: 10
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth.
# SupportedStyles: case, end
Expand Down Expand Up @@ -141,12 +141,13 @@ Layout/TrailingWhitespace:
Exclude:
- 'spec/searchworks_spec.rb'

# Offense count: 33
# Offense count: 32
Metrics/AbcSize:
Max: 56
Max: 58

# Offense count: 102
# Offense count: 97
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 795

Expand All @@ -155,24 +156,31 @@ Metrics/BlockLength:
Metrics/ClassLength:
Max: 377

# Offense count: 20
# Offense count: 18
Metrics/CyclomaticComplexity:
Max: 26
Max: 32

# Offense count: 118
# Offense count: 116
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 199

# Offense count: 32
# Configuration parameters: CountComments.
# Offense count: 31
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 52

# Offense count: 16
# Offense count: 14
Metrics/PerceivedComplexity:
Max: 20
Max: 25

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Naming/FileName:
Exclude:
- 'lib/stanford-mods.rb'

# Offense count: 24
# Configuration parameters: Blacklist.
Expand Down Expand Up @@ -206,7 +214,7 @@ Naming/PredicateName:

# Offense count: 2
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: io, id, to, by, on, in, at
# AllowedNames: io, id, to, by, on, in, at, ip, db
Naming/UncommunicativeMethodParamName:
Exclude:
- 'lib/stanford-mods/imprint.rb'
Expand Down Expand Up @@ -244,7 +252,7 @@ RSpec/BeforeAfterAll:
- 'spec/searchworks_subject_spec.rb'
- 'spec/searchworks_title_spec.rb'

# Offense count: 142
# Offense count: 134
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Expand Down Expand Up @@ -282,14 +290,15 @@ RSpec/DescribeClass:
- 'spec/sw_publication_spec.rb'

# Offense count: 14
# Cop supports --auto-correct.
RSpec/EmptyLineAfterFinalLet:
Exclude:
- 'spec/name_spec.rb'
- 'spec/origin_info_spec.rb'
- 'spec/physical_location_spec.rb'
- 'spec/sw_publication_spec.rb'

# Offense count: 148
# Offense count: 133
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
Expand All @@ -304,7 +313,8 @@ RSpec/ExampleLength:
- 'spec/searchworks_subject_spec.rb'
- 'spec/searchworks_title_spec.rb'

# Offense count: 114
# Offense count: 111
# Cop supports --auto-correct.
# Configuration parameters: CustomTransform, IgnoredWords.
RSpec/ExampleWording:
Exclude:
Expand All @@ -323,12 +333,13 @@ RSpec/FilePath:
- 'spec/lib/stanford-mods/coordinate_spec.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: .
# SupportedStyles: implicit, each, example
RSpec/HookArgument:
EnforcedStyle: each

# Offense count: 1105
# Offense count: 931
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
Expand All @@ -341,6 +352,7 @@ RSpec/InstanceVariable:
- 'spec/searchworks_title_spec.rb'

# Offense count: 2
# Cop supports --auto-correct.
RSpec/LetBeforeExamples:
Exclude:
- 'spec/origin_info_spec.rb'
Expand All @@ -356,7 +368,7 @@ RSpec/MultipleDescribes:
Exclude:
- 'spec/geo_spatial_spec.rb'

# Offense count: 114
# Offense count: 100
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Max: 9
Expand All @@ -366,7 +378,7 @@ RSpec/NamedSubject:
Exclude:
- 'spec/lib/stanford-mods/coordinate_spec.rb'

# Offense count: 38
# Offense count: 36
RSpec/NestedGroups:
Max: 5

Expand Down Expand Up @@ -408,7 +420,7 @@ Style/BlockDelimiters:
- 'lib/stanford-mods/searchworks_subjects.rb'
- 'spec/name_spec.rb'

# Offense count: 67
# Offense count: 65
Style/CommentedKeyword:
Exclude:
- 'lib/stanford-mods.rb'
Expand Down Expand Up @@ -508,6 +520,11 @@ Style/MultilineTernaryOperator:
Exclude:
- 'lib/stanford-mods/physical_location.rb'

# Offense count: 1
Style/MultipleComparison:
Exclude:
- 'lib/stanford-mods/origin_info.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedOctalStyle.
Expand All @@ -516,6 +533,15 @@ Style/NumericLiteralPrefix:
Exclude:
- 'spec/date_parsing_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'lib/stanford-mods/searchworks.rb'

# Offense count: 8
# Cop supports --auto-correct.
Style/PerlBackrefs:
Expand Down Expand Up @@ -598,7 +624,7 @@ Style/UnneededCondition:
- 'lib/stanford-mods/origin_info.rb'
- 'lib/stanford-mods/searchworks.rb'

# Offense count: 125
# Offense count: 124
# Cop supports --auto-correct.
# Configuration parameters: MinSize, WordRegex.
# SupportedStyles: percent, brackets
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -4,7 +4,7 @@ source 'https://rubygems.org'
gemspec

group :test, :development do
gem 'rubocop', require: false
gem 'rubocop', '~> 0.60.0', require: false
gem 'rubocop-rspec', require: false
gem 'coveralls', require: false
end
3 changes: 3 additions & 0 deletions lib/stanford-mods/coordinate.rb
Expand Up @@ -16,12 +16,14 @@ def initialize(value)
# @return [String] the coordinate in WKT/CQL ENVELOPE representation
def as_envelope
return unless valid?

"ENVELOPE(#{bounds[:min_x]}, #{bounds[:max_x]}, #{bounds[:max_y]}, #{bounds[:min_y]})"
end

# @return [String] the coordinate in Solr 4.x+ bbox-format representation
def as_bbox
return unless valid?

"#{bounds[:min_x]} #{bounds[:min_y]} #{bounds[:max_x]} #{bounds[:max_y]}"
end

Expand All @@ -44,6 +46,7 @@ def bounds
@bounds ||= begin
matches = cleaner_coordinate(value).match %r{\A(?<lat>[EW].+-+.+)\s*/\s*(?<lng>[NS].+-+.+)\Z}
return {} unless matches

min_x, max_x = matches['lat'].split(/-+/).map { |x| coord_to_decimal(x) }.minmax
min_y, max_y = matches['lng'].split(/-+/).map { |y| coord_to_decimal(y) }.minmax
{ min_x: min_x, min_y: min_y, max_x: max_x, max_y: max_y }
Expand Down
12 changes: 12 additions & 0 deletions lib/stanford-mods/date_parsing.rb
Expand Up @@ -32,13 +32,15 @@ def self.sortable_year_string_from_date_str(date_str)
# @return [Boolean] true if the year is between -999 and (current year + 1); false otherwise
def self.year_str_valid?(year_str)
return false unless year_str && (year_str.match(/^\d{1,4}$/) || year_str.match(/^-\d{1,3}$/))

(-1000 < year_str.to_i) && (year_str.to_i < Date.today.year + 2)
end

# true if the year is between -9999 and (current year + 1)
# @return [Boolean] true if the year is between -9999 and (current year + 1); false otherwise
def self.year_int_valid?(year)
return false unless year.is_a? Integer

(-1000 < year.to_i) && (year < Date.today.year + 2)
end

Expand All @@ -59,6 +61,7 @@ def date_str_for_display
return display_str_for_bc if orig_date_str.match(BC_REGEX)
# decade next in case there are 4 digits, e.g. 1950s
return display_str_for_decade if orig_date_str.match(DECADE_4CHAR_REGEXP) || orig_date_str.match(DECADE_S_REGEXP)

result = sortable_year_for_yyyy_or_yy
unless result
# try removing brackets between digits in case we have 169[5] or [18]91
Expand All @@ -81,6 +84,7 @@ def year_int_from_date_str
return if orig_date_str == '0000-00-00' # shpc collection has these useless dates
# B.C. first in case there are 4 digits, e.g. 1600 B.C.
return sortable_year_int_for_bc if orig_date_str.match(BC_REGEX)

result = sortable_year_for_yyyy_or_yy
result ||= sortable_year_for_decade # 19xx or 20xx
result ||= sortable_year_for_century
Expand All @@ -102,6 +106,7 @@ def sortable_year_string_from_date_str
return if orig_date_str == '0000-00-00' # shpc collection has these useless dates
# B.C. first in case there are 4 digits, e.g. 1600 B.C.
return sortable_year_str_for_bc if orig_date_str.match(BC_REGEX)

result = sortable_year_for_yyyy_or_yy
result ||= sortable_year_for_decade # 19xx or 20xx
result ||= sortable_year_for_century
Expand Down Expand Up @@ -144,6 +149,7 @@ def sortable_year_for_yyyy
# @return [String, nil] 4 digit year (e.g. 1865, 0950) if orig_date_str matches pattern, nil otherwise
def sortable_year_for_yy
return unless orig_date_str

slash_matches = orig_date_str.match(/\d{1,2}\/\d{1,2}\/\d{2}/)
if slash_matches
date_obj = Date.strptime(orig_date_str, '%m/%d/%y')
Expand Down Expand Up @@ -196,6 +202,7 @@ def display_str_for_decade
def sortable_year_for_century
return unless orig_date_str
return if orig_date_str =~ /B\.C\./

century_matches = orig_date_str.match(CENTURY_4CHAR_REGEXP)
if century_matches
return $1 + '00' if $1.length == 2
Expand All @@ -215,6 +222,7 @@ def sortable_year_for_century
def display_str_for_century
return unless orig_date_str
return if orig_date_str =~ /B\.C\./

century_str_matches = orig_date_str.match(CENTURY_WORD_REGEXP)
return century_str_matches.to_s if century_str_matches

Expand Down Expand Up @@ -262,6 +270,7 @@ def display_str_for_bc
# @return [String, nil] String sortable -ddd if orig_date_str matches pattern; nil otherwise
def sortable_year_str_for_early_numeric
return unless orig_date_str.match(EARLY_NUMERIC)

if orig_date_str =~ /^\-/
# negative number becomes x - 1000 for sorting; -005 for -995
num = orig_date_str[1..-1].to_i - 1000
Expand All @@ -275,6 +284,7 @@ def sortable_year_str_for_early_numeric
# @return [Integer, nil] Integer sortable -ddd if orig_date_str matches pattern; nil otherwise
def sortable_year_int_for_early_numeric
return orig_date_str.to_i if orig_date_str.match(EARLY_NUMERIC)

orig_date_str.to_i if orig_date_str =~ /^-\d{4}$/
end

Expand All @@ -290,6 +300,7 @@ def display_str_for_early_numeric
return '1 B.C.' if orig_date_str == '0'
# negative number becomes B.C.
return "#{orig_date_str[1..-1].to_i + 1} B.C." if orig_date_str =~ /^\-/

# remove leading 0s from early dates
"#{orig_date_str.to_i} A.D."
end
Expand All @@ -304,6 +315,7 @@ def year_via_ruby_parsing
# need more in string than only 2 digits
return if orig_date_str.match(/^\d\d$/) || orig_date_str.match(/^\D*\d\d\D*$/)
return if orig_date_str =~ /\d\s*B.C./ # skip B.C. dates

date_obj = Date.parse(orig_date_str)
date_obj.year.to_s
rescue ArgumentError
Expand Down

0 comments on commit ea87088

Please sign in to comment.