diff --git a/.rubocop.yml b/.rubocop.yml index 3226c60..62bcf94 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -25,3 +25,6 @@ Metrics/PerceivedComplexity: Metrics/ClassLength: Max: 200 + +Layout/FirstArrayElementIndentation: + EnforcedStyle: consistent diff --git a/lib/overpass_parser/nodes/out.rb b/lib/overpass_parser/nodes/out.rb index 0a46c64..9155bcd 100644 --- a/lib/overpass_parser/nodes/out.rb +++ b/lib/overpass_parser/nodes/out.rb @@ -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) diff --git a/lib/overpass_parser/nodes/query_objects.rb b/lib/overpass_parser/nodes/query_objects.rb index 79f48b5..c545f67 100644 --- a/lib/overpass_parser/nodes/query_objects.rb +++ b/lib/overpass_parser/nodes/query_objects.rb @@ -7,7 +7,7 @@ module OverpassParser module Nodes - class QueryObjects < T::Struct + class QueryObjects < T::InexactStruct include T::Struct::ActsAsComparable extend T::Sig @@ -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 diff --git a/lib/overpass_parser/nodes/query_recurse.rb b/lib/overpass_parser/nodes/query_recurse.rb index 9d45ba1..1333439 100644 --- a/lib/overpass_parser/nodes/query_recurse.rb +++ b/lib/overpass_parser/nodes/query_recurse.rb @@ -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 diff --git a/lib/overpass_parser/nodes/query_union.rb b/lib/overpass_parser/nodes/query_union.rb index ad3cade..9579cc9 100644 --- a/lib/overpass_parser/nodes/query_union.rb +++ b/lib/overpass_parser/nodes/query_union.rb @@ -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 diff --git a/lib/overpass_parser/nodes/selectors.rb b/lib/overpass_parser/nodes/selectors.rb index 8bc4d24..831741c 100644 --- a/lib/overpass_parser/nodes/selectors.rb +++ b/lib/overpass_parser/nodes/selectors.rb @@ -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 diff --git a/test/overpass_parser/visitor_test.rb b/test/overpass_parser/visitor_test.rb index 24662b1..c54d52e 100644 --- a/test/overpass_parser/visitor_test.rb +++ b/test/overpass_parser/visitor_test.rb @@ -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] ) @@ -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 @@ -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] ) @@ -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] @@ -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] ) @@ -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: '_' ) ],