Skip to content

Commit

Permalink
Merge pull request #14 from mattrayner/mattrayner/update-filtering-to…
Browse files Browse the repository at this point in the history
…-support-multiple-types

Add the ability to filter nodes with multiple types
  • Loading branch information
callumnj authored Apr 5, 2018
2 parents c6a45bc + b0030a1 commit dc1a7a9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 9 deletions.
15 changes: 9 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ Metrics/LineLength:
Max: 120
IgnoredPatterns: ['\A#', '\A([ ]{2}|[ ]{4})#']

Style/SpaceBeforeFirstArg:
Style/EachWithObject:
Enabled: false

Layout/SpaceBeforeFirstArg:
Enabled: false

Style/BracesAroundHashParameters:
Enabled: false

Style/IndentHash:
Layout/IndentHash:
EnforcedStyle: consistent

Style/AlignHash:
Layout/AlignHash:
Severity: fatal
Enabled: true
EnforcedHashRocketStyle: table
EnforcedColonStyle: table

Style/AlignParameters:
Layout/AlignParameters:
EnforcedStyle: with_fixed_indentation

Style/StringLiterals:
Expand All @@ -32,13 +35,13 @@ Style/CollectionMethods:
detect: 'find'
find_all: 'select'

Style/DotPosition:
Layout/DotPosition:
EnforcedStyle: leading

Style/DoubleNegation:
Enabled: false

Style/SpaceAroundOperators:
Layout/SpaceAroundOperators:
# When true, allows most uses of extra spacing if the intent is to align
# with an operator on the previous or next line, not counting empty lines
# or comment lines.
Expand Down
2 changes: 1 addition & 1 deletion lib/parliament/ntriple/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Parliament
module NTriple
VERSION = '0.2.1'.freeze
VERSION = '0.3.0'.freeze
end
end
11 changes: 9 additions & 2 deletions lib/parliament/response/ntriple_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ def filter(*types)

unless types.empty?
@nodes.each do |node|
type_index = node.blank? ? types.index(::Grom::Node::BLANK) : types.index(node.type)
node_types = node.blank? ? Array(::Grom::Node::BLANK) : Array(node.type)

filtered_objects[type_index] << node unless type_index.nil?
indexes = node_types.reduce([]) do |memo, type|
index = types.index(type)
memo << index if index

memo
end

indexes.each { |index| filtered_objects[index] << node }
end
end

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions spec/parliament/response/ntriple_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@
expect(node.type).to eq('http://id.ukpds.org/schema/Person')
end
end

it 'filters nodes that appear in multiple types' do
filtered_response = @response.filter('http://id.ukpds.org/schema/Group', 'http://id.ukpds.org/schema/FormalBody')
expect(filtered_response.size).to eq(2)

filtered_response.each do |filtered_nodes|
expect(filtered_nodes.size).to eq(2)

filtered_nodes.each do |node|
expect(node.type).to eq(%w(http://id.ukpds.org/schema/Group http://id.ukpds.org/schema/FormalBody))
end
end
end
end

describe '#sort_by' do
Expand Down

0 comments on commit dc1a7a9

Please sign in to comment.