Skip to content

Commit 477e4cb

Browse files
committed
DEVOPS-247: Address rubocop issues.
1 parent 571aa31 commit 477e4cb

File tree

6 files changed

+181
-143
lines changed

6 files changed

+181
-143
lines changed

.rubocop_todo.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2019-11-03 23:25:34 +0000 using RuboCop version 0.76.0.
3+
# on 2019-11-04 18:38:39 +0000 using RuboCop version 0.76.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 3
9+
# Offense count: 4
1010
Metrics/AbcSize:
1111
Max: 44
1212

13-
# Offense count: 8
13+
# Offense count: 10
1414
# Configuration parameters: CountComments, ExcludedMethods.
1515
# ExcludedMethods: refine
1616
Metrics/BlockLength:
17-
Max: 707
17+
Max: 786
1818

1919
# Offense count: 2
2020
# Configuration parameters: CountComments.
2121
Metrics/ClassLength:
22-
Max: 218
22+
Max: 228
2323

2424
# Offense count: 1
2525
Metrics/CyclomaticComplexity:
2626
Max: 8
2727

28-
# Offense count: 9
28+
# Offense count: 11
2929
# Configuration parameters: CountComments, ExcludedMethods.
3030
Metrics/MethodLength:
3131
Max: 51
@@ -39,10 +39,12 @@ Metrics/ParameterLists:
3939
Metrics/PerceivedComplexity:
4040
Max: 8
4141

42-
# Offense count: 8
42+
# Offense count: 10
4343
# Rubocop not hip to RDoc directives.
4444
Style/CommentedKeyword:
4545
Exclude:
46+
- 'lib/address_parameter.rb'
47+
- 'lib/address_similarity_parameters.rb'
4648
- 'lib/bad_request_error.rb'
4749
- 'lib/bad_request_format_error.rb'
4850
- 'lib/document_parameters.rb'
@@ -67,14 +69,14 @@ Style/IfUnlessModifier:
6769
Exclude:
6870
- 'lib/rosette_api.rb'
6971

70-
# Offense count: 12
72+
# Offense count: 14
7173
# Cop supports --auto-correct.
7274
# Configuration parameters: .
7375
# SupportedStyles: compact, exploded
7476
Style/RaiseArgs:
7577
EnforcedStyle: compact
7678

77-
# Offense count: 9
79+
# Offense count: 15
7880
# Cop supports --auto-correct.
7981
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
8082
# URISchemes: http, https

examples/address_similarity.rb

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1+
# frozen_string_literal: true
2+
13
require 'rosette_api'
24

35
api_key, url = ARGV
46

5-
if !url
6-
rosette_api = RosetteAPI.new(api_key)
7-
else
8-
rosette_api = RosetteAPI.new(api_key, url)
9-
end
7+
rosette_api = if url
8+
RosetteAPI.new(api_key, url)
9+
else
10+
RosetteAPI.new(api_key)
11+
end
1012

1113
begin
1214
address1 = AddressParameter.new(
13-
'houseNumber': '1600',
14-
'road': 'Pennsylvania Ave NW',
15-
'city': 'Washington',
16-
'state': 'DC',
17-
'postCode': '20500'
15+
'house_number': '1600',
16+
'road': 'Pennsylvania Ave NW',
17+
'city': 'Washington',
18+
'state': 'DC',
19+
'post_code': '20500'
1820
)
1921
address2 = AddressParameter.new(
20-
'houseNumber': '160',
21-
'road': 'Pennsilvana Avenue',
22-
'city': 'Washington',
23-
'state': 'D.C.',
24-
'postCode': '20500'
22+
'house_number': '160',
23+
'road': 'Pennsilvana Avenue',
24+
'city': 'Washington',
25+
'state': 'D.C.',
26+
'post_code': '20500'
2527
)
2628
params = AddressSimilarityParameters.new(address1, address2)
2729
response = rosette_api.get_address_similarity(params)
2830
puts JSON.pretty_generate(response)
29-
rescue RosetteAPIError => rosette_api_error
30-
printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message)
31+
rescue RosetteAPIError => e
32+
printf('Rosette API Error (%<status_code>s): %<message>s',
33+
status_code: e.status_code,
34+
message: e.message)
3135
end

lib/address_parameter.rb

Lines changed: 82 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,85 @@
1+
# frozen_string_literal: true
2+
13
# This class represents an address in Rosette API.
24
class AddressParameter
3-
# house (optional)
4-
attr_accessor :house
5-
# houseNumber (optional)
6-
attr_accessor :houseNumber
7-
# road (optional)
8-
attr_accessor :road
9-
# unit (optional)
10-
attr_accessor :unit
11-
# level (optional)
12-
attr_accessor :level
13-
# staircase (optional)
14-
attr_accessor :staircase
15-
# entrance (optional)
16-
attr_accessor :entrance
17-
# suburb (optional)
18-
attr_accessor :suburb
19-
# cityDistrict (optional)
20-
attr_accessor :cityDistrict
21-
# city (optional)
22-
attr_accessor :city
23-
# island (optional)
24-
attr_accessor :island
25-
# stateDistrict (optional)
26-
attr_accessor :stateDistrict
27-
# state (optional)
28-
attr_accessor :state
29-
# countryRegion (optional)
30-
attr_accessor :countryRegion
31-
# country (optional)
32-
attr_accessor :country
33-
# worldRegion (optional)
34-
attr_accessor :worldRegion
35-
# postCode (optional)
36-
attr_accessor :postCode
37-
# poBox (optional)
38-
attr_accessor :poBox
5+
# house (optional)
6+
attr_accessor :house
7+
# house_number (optional)
8+
attr_accessor :house_number
9+
# road (optional)
10+
attr_accessor :road
11+
# unit (optional)
12+
attr_accessor :unit
13+
# level (optional)
14+
attr_accessor :level
15+
# staircase (optional)
16+
attr_accessor :staircase
17+
# entrance (optional)
18+
attr_accessor :entrance
19+
# suburb (optional)
20+
attr_accessor :suburb
21+
# city_district (optional)
22+
attr_accessor :city_district
23+
# city (optional)
24+
attr_accessor :city
25+
# island (optional)
26+
attr_accessor :island
27+
# state_district (optional)
28+
attr_accessor :state_district
29+
# state (optional)
30+
attr_accessor :state
31+
# country_region (optional)
32+
attr_accessor :country_region
33+
# country (optional)
34+
attr_accessor :country
35+
# world_region (optional)
36+
attr_accessor :world_region
37+
# post_code (optional)
38+
attr_accessor :post_code
39+
# po_box (optional)
40+
attr_accessor :po_box
3941

4042
def initialize(options = {}) #:notnew:
4143
options = {
42-
house: nil,
43-
houseNumber: nil,
44-
road: nil,
45-
unit: nil,
46-
level: nil,
47-
staircase: nil,
48-
entrance: nil,
49-
suburb: nil,
50-
cityDistrict: nil,
51-
city: nil,
52-
island: nil,
53-
stateDistrict: nil,
54-
state: nil,
55-
countryRegion: nil,
56-
country: nil,
57-
worldRegion: nil,
58-
postCode: nil,
59-
poBox: nil
44+
house: nil,
45+
house_number: nil,
46+
road: nil,
47+
unit: nil,
48+
level: nil,
49+
staircase: nil,
50+
entrance: nil,
51+
suburb: nil,
52+
city_district: nil,
53+
city: nil,
54+
island: nil,
55+
state_district: nil,
56+
state: nil,
57+
country_region: nil,
58+
country: nil,
59+
world_region: nil,
60+
post_code: nil,
61+
po_box: nil
6062
}.update options
6163
@house = options[:house]
62-
@houseNumber = options[:houseNumber]
64+
@house_number = options[:house_number]
6365
@road = options[:road]
6466
@unit = options[:unit]
6567
@level = options[:level]
6668
@staircase = options[:staircase]
6769
@entrance = options[:entrance]
6870
@suburb = options[:suburb]
69-
@cityDistrict = options[:cityDistrict]
71+
@city_district = options[:city_district]
7072
@city = options[:city]
7173
@island = options[:island]
72-
@stateDistrict = options[:stateDistrict]
74+
@state_district = options[:state_district]
7375
@state = options[:state]
74-
@countryRegion = options[:countryRegion]
76+
@country_region = options[:country_region]
7577
@country = options[:country]
76-
@worldRegion = options[:worldRegion]
77-
@postCode = options[:postCode]
78-
@poBox = options[:poBox]
78+
@world_region = options[:world_region]
79+
@post_code = options[:post_code]
80+
@po_box = options[:po_box]
7981
end
80-
82+
8183
# Converts this class to Hash with its keys in lower CamelCase.
8284
#
8385
# Returns the new Hash.
@@ -92,24 +94,24 @@ def load_param
9294
# Returns the new Hash.
9395
def to_hash
9496
{
95-
house: @house,
96-
houseNumber: @houseNumber,
97-
road: @road,
98-
unit: @unit,
99-
level: @level,
100-
staircase: @staircase,
101-
entrance: @entrance,
102-
suburb: @suburb,
103-
cityDistrict: @cityDistrict,
104-
city: @city,
105-
island: @island,
106-
stateDistrict: @stateDistrict,
107-
state: @state,
108-
countryRegion: @countryRegion,
109-
country: @country,
110-
worldRegion: @worldRegion,
111-
postCode: @postCode,
112-
poBox: @poBox
97+
house: @house,
98+
house_number: @house_number,
99+
road: @road,
100+
unit: @unit,
101+
level: @level,
102+
staircase: @staircase,
103+
entrance: @entrance,
104+
suburb: @suburb,
105+
city_district: @city_district,
106+
city: @city,
107+
island: @island,
108+
state_district: @state_district,
109+
state: @state,
110+
country_region: @country_region,
111+
country: @country,
112+
world_region: @world_region,
113+
post_code: @post_code,
114+
po_box: @po_box
113115
}
114116
end
115117
end

lib/address_similarity_parameters.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require_relative 'bad_request_error'
24
require_relative 'address_parameter'
35

@@ -14,20 +16,25 @@ def initialize(address1, address2) #:notnew:
1416
@address2 = address2
1517
end
1618

17-
# Validates the parameters by checking if address1 and address2 are instances of AddressParameter.
19+
# Validates the parameters by checking if address1 and address2 are instances
20+
# of AddressParameter.
1821
def validate_params
19-
raise BadRequestError.new('address1 option can only be an instance of an AddressParameter') if [AddressParameter].none? { |clazz| @address1.is_a? clazz }
20-
raise BadRequestError.new('address2 option can only be an instance of an AddressParameter') if [AddressParameter].none? { |clazz| @address2.is_a? clazz }
22+
a1_msg = 'address1 option can only be an instance of an AddressParameter'
23+
raise BadRequestError.new(a1_msg) if [AddressParameter].none? { |clazz| @address1.is_a? clazz }
24+
25+
a2_msg = 'address2 option can only be an instance of an AddressParameter'
26+
raise BadRequestError.new(a2_msg) if [AddressParameter].none? { |clazz| @address2.is_a? clazz }
2127
end
2228

2329
# Converts this class to Hash with its keys in lower CamelCase.
2430
#
2531
# Returns the new Hash.
2632
def load_params
2733
validate_params
28-
to_hash.reject { |_key, value| value.nil? }
29-
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
30-
.to_h
34+
to_hash
35+
.reject { |_key, value| value.nil? }
36+
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
37+
.to_h
3138
end
3239

3340
# Converts this class to Hash.

lib/rosette_api.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class RosetteAPI
3333
# Rosette API name-similarity endpoint
3434
NAME_SIMILARITY_ENDPOINT = '/name-similarity'
3535
# Rosette API address-similarity endpoint
36-
ADDRESS_SIMILARITY_ENDPOINT = '/address-similarity'.freeze
36+
ADDRESS_SIMILARITY_ENDPOINT = '/address-similarity'
3737
# Rosette API tokens endpoint
3838
TOKENS_ENDPOINT = '/tokens'
3939
# Rosette API sentences endpoint
@@ -334,15 +334,19 @@ def get_name_similarity(params)
334334
#
335335
# ==== Attributes
336336
#
337-
# * +params+ - AddressSimilarityParameters helps to build the request body in RequestBuilder.
337+
# * +params+ - AddressSimilarityParameters helps to build the request body in
338+
# RequestBuilder.
338339
#
339340
# Returns the confidence score of matching 2 addresses.
340341
def get_address_similarity(params)
341-
check_params params, 'Expects a AddressSimilarityParameters type as an argument', AddressSimilarityParameters
342+
check_params params,
343+
'Expects a AddressSimilarityParameters type as an argument',
344+
AddressSimilarityParameters
342345

343346
params = params.load_params
344347

345-
RequestBuilder.new(@user_key, @alternate_url + ADDRESS_SIMILARITY_ENDPOINT, @http_client, BINDING_VERSION, params, @url_parameters)
348+
RequestBuilder.new(@user_key, @alternate_url + ADDRESS_SIMILARITY_ENDPOINT,
349+
@http_client, BINDING_VERSION, params, @url_parameters)
346350
.send_post_request
347351
end
348352

0 commit comments

Comments
 (0)