Skip to content

Commit

Permalink
Code lint
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Apr 13, 2024
1 parent 297828e commit 9b33c47
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ Metrics/PerceivedComplexity:

Metrics/ClassLength:
Max: 200

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent
1 change: 0 additions & 1 deletion lib/overpass_parser/nodes/out.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Out < T::Struct
).returns(T.nilable(String))
end
def to_sql(sql_dialect)
coordinates = %w[skel body meta].include?(@level_of_details)
way_member_nodes = %w[skel body meta].include?(@level_of_details)
relations_members = %w[skel body meta].include?(@level_of_details)
tags = %w[body tags meta].include?(@level_of_details)
Expand Down
13 changes: 8 additions & 5 deletions lib/overpass_parser/nodes/query_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

module OverpassParser
module Nodes
class QueryObjects < T::Struct
class QueryObjects < T::InexactStruct
include T::Struct::ActsAsComparable
extend T::Sig

Expand All @@ -18,10 +18,13 @@ class QueryObjects < T::Struct
const :asignation, T.nilable(String)

def initialize(object_type:, selectors: nil, filters: nil, set: nil, asignation: nil)
@object_type = object_type
@selectors = selectors
@filters = filters
@set = set
super(
object_type: object_type,
selectors: selectors,
filters: filters,
set: set,
asignation: asignation,
)
@asignation = asignation.nil? ? "_#{Digest::SHA1.hexdigest(inspect)}" : "_#{asignation}"
end

Expand Down
5 changes: 4 additions & 1 deletion lib/overpass_parser/nodes/query_recurse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ class QueryRecurse < T::Struct
const :asignation, T.nilable(String)

def initialize(recurse:, asignation: nil)
@recurse = recurse
super(
recurse: recurse,
asignation: asignation,
)
@asignation = asignation.nil? ? "_#{Digest::SHA1.hexdigest(inspect)}" : "_#{asignation}"
end

Expand Down
5 changes: 4 additions & 1 deletion lib/overpass_parser/nodes/query_union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class QueryUnion < T::Struct
const :asignation, T.nilable(String)

def initialize(queries:, asignation: nil)
@queries = queries
super(
queries: queries,
asignation: asignation,
)
@asignation = asignation.nil? ? "_#{Digest::SHA1.hexdigest(inspect)}" : "_#{asignation}"
end

Expand Down
12 changes: 7 additions & 5 deletions lib/overpass_parser/nodes/selectors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class Selector < T::InexactStruct
).void
end
def initialize(key:, not_: false, operator: nil, value: nil)
@key = key
# Does not use boolean, as not comparable
@not_ = not_ == true ? 1 : 0
@operator = operator
@value = !operator.nil? && ['~', '!~'].include?(operator) ? Regexp.new(T.must(value)) : value
super(
key: key,
# Does not use boolean, as not comparable
not_: not_ == true ? 1 : 0,
operator: operator,
value: !operator.nil? && ['~', '!~'].include?(operator) ? Regexp.new(T.must(value)) : value,
)
end

sig do
Expand Down
26 changes: 14 additions & 12 deletions test/overpass_parser/visitor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def test_quote
assert_equal(
QueryObjects.new(
object_type: 'node',
selectors: [
selectors: Selectors.new([
Selector.new(key: 'highway', value: 'primary', operator: '='),
Selector.new(key: 'operator', value: "Commune d'Anglet", operator: '=')
]
])
),
tree[0].queries[0]
)
Expand All @@ -22,7 +22,7 @@ def test_quote
def test_selector_key
tree = OverpassParser.tree('node[highway];')
assert_equal(
QueryObjects.new(object_type: 'node', selectors: [Selector.new(key: 'highway', not_: false)]),
QueryObjects.new(object_type: 'node', selectors: Selectors.new([Selector.new(key: 'highway', not_: false)])),
tree[0].queries[0]
)
end
Expand All @@ -32,10 +32,10 @@ def test_selector_key_value
assert_equal(
QueryObjects.new(
object_type: 'node',
selectors: [
selectors: Selectors.new([
Selector.new(key: 'highway', value: 'primary', operator: '='),
Selector.new(key: 'ref', value: '33', operator: '=')
]
])
),
tree[0].queries[0]
)
Expand All @@ -46,7 +46,7 @@ def test_selector_set
assert_equal(
QueryObjects.new(
object_type: 'node',
selectors: [Selector.new(key: 'highway', value: 'primary', operator: '=')],
selectors: Selectors.new([Selector.new(key: 'highway', value: 'primary', operator: '=')]),
set: '_'
),
tree[0].queries[0]
Expand All @@ -58,7 +58,7 @@ def test_filter_arround
assert_equal(
QueryObjects.new(
object_type: 'node',
filters: [Filter.new(around: FilterAround.new(core: 'a', radius: 100.0))]
filters: Filters.new([Filter.new(around: FilterAround.new(core: 'a', radius: 100.0))])
),
tree[0].queries[0]
)
Expand All @@ -83,17 +83,19 @@ def test_full
Request.new(
timeout: 25,
queries: [
QueryObjects.new(object_type: 'area', filters: [Filter.new(ids: [3_600_000_001])], asignation: 'a'),
QueryObjects.new(object_type: 'area', filters: [Filter.new(ids: [3_600_000_002])], asignation: 'b'),
QueryObjects.new(object_type: 'area', filters: Filters.new([Filter.new(ids: [3_600_000_001])]),
asignation: 'a'),
QueryObjects.new(object_type: 'area', filters: Filters.new([Filter.new(ids: [3_600_000_002])]),
asignation: 'b'),
QueryObjects.new(
object_type: 'relation',
selectors: [Selector.new(key: 'name', value: 'En aban !', operator: '=')],
filters: [Filter.new(around: FilterAround.new(core: '_', radius: 500.0))]
selectors: Selectors.new([Selector.new(key: 'name', value: 'En aban !', operator: '=')]),
filters: Filters.new([Filter.new(around: FilterAround.new(core: '_', radius: 500.0))])
),
QueryRecurse.new(recurse: '>'),
QueryObjects.new(
object_type: 'nwr',
selectors: [Selector.new(key: 'highway', value: 'bus_stop', operator: '=')],
selectors: Selectors.new([Selector.new(key: 'highway', value: 'bus_stop', operator: '=')]),
set: '_'
)
],
Expand Down

0 comments on commit 9b33c47

Please sign in to comment.