parliament-ntriple 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5be886f1f69356bed0802c4740ea0402e7577b3f
4
+ data.tar.gz: f2ae08c0f9a87c0c1cd18cf130b58231d3832e92
5
+ SHA512:
6
+ metadata.gz: 7ff744039412f1ca938b1b471fc5d55e193b6f539911593561f1eaf41387d3fd2e7ecc98acdc0a2d73d813032f591d4f423f39f0944f6b7b47a2ce55be478ad8
7
+ data.tar.gz: e37d51ba13d56af9e433a4c4e65d833b74401577eec212bb619e857d3ece333d966b701a8ba848b7ee06acaff3ca409b69dffee9bc097da6e39b987d9ec00a97
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ .idea
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.hound.yml ADDED
@@ -0,0 +1,4 @@
1
+ ruby:
2
+ config_file: .rubocop.yml
3
+
4
+ fail_on_violations: true
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,55 @@
1
+ Metrics/LineLength:
2
+ Description: 'Limit lines to 120 characters.'
3
+ Max: 120
4
+ IgnoredPatterns: ['\A#', '\A([ ]{2}|[ ]{4})#']
5
+
6
+ Style/SpaceBeforeFirstArg:
7
+ Enabled: false
8
+
9
+ Style/BracesAroundHashParameters:
10
+ Enabled: false
11
+
12
+ Style/IndentHash:
13
+ EnforcedStyle: consistent
14
+
15
+ Style/AlignHash:
16
+ Severity: fatal
17
+ Enabled: true
18
+ EnforcedHashRocketStyle: table
19
+ EnforcedColonStyle: table
20
+
21
+ Style/AlignParameters:
22
+ EnforcedStyle: with_fixed_indentation
23
+
24
+ Style/StringLiterals:
25
+ EnforcedStyle: single_quotes
26
+
27
+ Style/CollectionMethods:
28
+ PreferredMethods:
29
+ collect: 'map'
30
+ collect!: 'map!'
31
+ inject: 'reduce'
32
+ detect: 'find'
33
+ find_all: 'select'
34
+
35
+ Style/DotPosition:
36
+ EnforcedStyle: leading
37
+
38
+ Style/DoubleNegation:
39
+ Enabled: false
40
+
41
+ Style/SpaceAroundOperators:
42
+ # When true, allows most uses of extra spacing if the intent is to align
43
+ # with an operator on the previous or next line, not counting empty lines
44
+ # or comment lines.
45
+ AllowForAlignment: true
46
+
47
+ Style/FrozenStringLiteralComment:
48
+ Enabled: false
49
+
50
+ AllCops:
51
+ Exclude:
52
+ - '*.gemspec'
53
+ - 'vendor/**/*'
54
+ - 'spec/**/*'
55
+ - 'tmp/**/*'
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mattrayner1@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in parliament-ntriple.gemspec
4
+ gemspec
5
+
6
+ # Include coveralls for CI coverage reports
7
+ gem 'coveralls', require: false
8
+ gem 'parliament-grom-decorators', path: '../parliament-grom-decorators'
9
+ gem 'parliament-ruby', path: '../parliament-ruby'
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2016-2017 United Kingdom Parliament
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Parliament::NTriple
2
+
3
+ [parliament-ntriple](http://rubygems.org/gems/parliament-ntriple) is a gem created by the [Parliamentary Digital Service](https://www.parliament.uk/mps-lords-and-offices/offices/bicameral/parliamentary-digital-service/) to allow processing of n-triple data from parliamentary APIs. This gem is effectively an extension of our [parliament-ruby](http://rubygems.org/gems/parliament-ruby) gem.
4
+
5
+ > **NOTE:** This gem is in active development and is likely to change at short notice. It is not recommended that you use this in any production environment.
6
+
7
+ ## Requirements
8
+ [parliament-ntriple](http://github.com/ukparliament/parliament-ntriple) requires the following:
9
+ * [Ruby](https://www.ruby-lang.org/en/)
10
+ * [Bundler](http://http://bundler.io/)
11
+
12
+ ## Installation
13
+
14
+ This gem is currently not available on RubyGems. To use it in an application, install it directly from GitHub via your Gemfile
15
+ ```bash
16
+ gem 'parliament-ntriple', git: 'https://github.com/ukparliament/parliament-ntriple.git', branch: 'master'
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ This gem's main function is to process n-triple data from parliamentary APIs.
22
+
23
+ > **Note:** Comprehensive class documentation can be found on [rubydocs](http://www.rubydoc.info/github/ukparliament/parliament-ntriple/master/file/README.md).
24
+
25
+ ## Getting Started with Development
26
+ To clone the repository and set up the dependencies, run the following:
27
+ ```bash
28
+ git clone https://github.com/ukparliament/parliament-ntriple.git
29
+ cd parliament-ntriple
30
+ bundle install
31
+ ```
32
+
33
+ ### Running the tests
34
+ We use [RSpec](http://rspec.info/) as our testing framework and tests can be run using:
35
+ ```bash
36
+ bundle exec rake
37
+ ```
38
+
39
+ ## Contributing
40
+ If you wish to submit a bug fix or feature, you can create a pull request and it will be merged pending a code review.
41
+
42
+ 1. Fork the repository
43
+ 1. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 1. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 1. Push to the branch (`git push origin my-new-feature`)
46
+ 1. Ensure your changes are tested using [Rspec](http://rspec.info/)
47
+ 1. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'parliament/ntriple'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ module Parliament
2
+ module Builder
3
+ # N-Triple response builder, allowing the user to build a Parliament::Response::NTripleResponse from n-triple data.
4
+ #
5
+ # @since 0.1.0
6
+ class NTripleResponseBuilder < Parliament::Builder::BaseResponseBuilder
7
+ # Creates an instance of Parliament::Builder::NTripleResponseBuilder.
8
+ #
9
+ # @see Parliament::BaseResponse#initialize
10
+ #
11
+ # @param [HTTPResponse] response an HTTP response containing n-triple data.
12
+ # @param [Module] decorators the decorator module to provide alias methods to the resulting objects.
13
+ # @example Using the Grom Decorators module
14
+ # Parliament::Builder::NTripleResponseBuilder.new(response: <#HTTPResponse>, decorators: Parliament::Grom::Decorator)
15
+ def initialize(response:, decorators: nil)
16
+ @decorators = decorators
17
+
18
+ super
19
+ end
20
+
21
+ # Builds a Parliament::Response::NTripleResponse from the n-triple data.
22
+ #
23
+ # @return [Parliament::Response::NTripleResponse] a Parliament::Response::NTripleResponse containing decorated Grom::Node objects.
24
+ def build
25
+ objects = ::Grom::Reader.new(@response.body).objects
26
+ objects.map! { |object| @decorators.decorate(object) } unless @decorators.nil?
27
+
28
+ Parliament::Response::NTripleResponse.new(objects)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ require 'parliament'
2
+ require 'grom'
3
+
4
+ require 'parliament/ntriple/version'
5
+ require 'parliament/ntriple/utils'
6
+ require 'parliament/response/ntriple_response'
7
+ require 'parliament/builder/ntriple_response_builder'
8
+
9
+ # Namespace for classes and modules that handle connections to, and processing of data from the parliamentary API.
10
+ # @since 0.1.0
11
+ module Parliament
12
+ # NTriple namespace
13
+ # @since 0.1.0
14
+ module NTriple
15
+ end
16
+ end
@@ -0,0 +1,137 @@
1
+ module Parliament
2
+ module NTriple
3
+ # Namespace for helper methods used with parliament-ruby.
4
+ #
5
+ # @since 0.6.0
6
+ module Utils
7
+ # Sort an Array of Objects in ascending order. The major difference between this implementation of sort_by and the
8
+ # standard one is that our implementation includes objects that return nil for our parameter values.
9
+ #
10
+ # @see Parliament::NTriple::Utils.reverse_sort_by
11
+ #
12
+ # @example Sorting a list of objects by date
13
+ # response = parliament.people('123').get.filter('http://id.ukpds.org/schema/Person')
14
+ #
15
+ # objects = response.first.incumbencies
16
+ #
17
+ # args = {
18
+ # list: objects,
19
+ # parameters: [:endDate],
20
+ # prepend_rejected: false
21
+ # }
22
+ #
23
+ # sorted_list = Parliament::NTriple::Util.sort_by(args)
24
+ #
25
+ # sorted_list.each { |incumbency| puts incumbency.respond_to?(:endDate) ? incumbency.endDate : 'Current' }
26
+ # # http://id.ukpds.org/1121 - 1981-07-31
27
+ # # http://id.ukpds.org/5678 - 1991-03-15
28
+ # # http://id.ukpds.org/1234 - 1997-01-01
29
+ # # http://id.ukpds.org/9101 - 2011-09-04
30
+ # # http://id.ukpds.org/3141 - Current
31
+ #
32
+ # @param [Hash] args a hash of arguments.
33
+ # @option args [Array<Object>] :list the 'list' which we are sorting.
34
+ # @option args [Array<Symbol>] :parameters an array of parameters we are sorting by.
35
+ # @option args [Boolean] :prepend_rejected (true) should objects that do not respond to our parameters be prepended?
36
+ #
37
+ # @return [Array<Object>] a sorted array of objects using the args passed in.
38
+ def self.sort_by(args)
39
+ rejected = []
40
+ args = sort_defaults.merge(args)
41
+ list = args[:list].dup
42
+ parameters = args[:parameters]
43
+
44
+ list, rejected = prune_list(list, rejected, parameters)
45
+
46
+ list = sort_list(list, parameters)
47
+
48
+ # Any rejected (nil) values will be added to the start of the result unless specified otherwise
49
+ args[:prepend_rejected] ? rejected.concat(list) : list.concat(rejected)
50
+ end
51
+
52
+ # Sort an Array of Objects in descending order. Largely, this implementation runs Parliament::NTriple::Utils.sort_by and
53
+ # calls reverse! on the result.
54
+ #
55
+ # @see Parliament::NTriple::Utils.sort_by
56
+ #
57
+ # @example Sorting a list of objects by date
58
+ # response = parliament.people('123').get.filter('http://id.ukpds.org/schema/Person')
59
+ #
60
+ # objects = response.first.incumbencies
61
+ #
62
+ # args = {
63
+ # list: objects,
64
+ # parameters: [:endDate],
65
+ # prepend_rejected: false
66
+ # }
67
+ #
68
+ # sorted_list = Parliament::NTriple::Util.reverse_sort_by(args)
69
+ #
70
+ # sorted_list.each { |incumbency| puts incumbency.respond_to?(:endDate) ? incumbency.endDate : 'Current' }
71
+ # # http://id.ukpds.org/3141 - Current
72
+ # # http://id.ukpds.org/9101 - 2011-09-04
73
+ # # http://id.ukpds.org/1234 - 1997-01-01
74
+ # # http://id.ukpds.org/5678 - 1991-03-15
75
+ # # http://id.ukpds.org/1121 - 1981-07-31
76
+ #
77
+ # @param [Hash] args a hash of arguments.
78
+ # @option args [Array<Object>] :list the 'list' which we are sorting.
79
+ # @option args [Array<Symbol>] :parameters an array of parameters we are sorting by.
80
+ # @option args [Boolean] :prepend_rejected (true) should objects that do not respond to our parameters be prepended?
81
+ #
82
+ # @return [Array<Object>] a sorted array of objects using the args passed in.
83
+ def self.reverse_sort_by(args)
84
+ Parliament::NTriple::Utils.sort_by(args).reverse!
85
+ end
86
+
87
+ # Default arguments hash for #sort_by and #reverse_sort_by.
88
+ #
89
+ # @see Parliament::NTriple::Utils.sort_by
90
+ # @see Parliament::NTriple::Utils.reverse_sort_by
91
+ #
92
+ # @return [Hash] default arguments used in sorting methods.
93
+ def self.sort_defaults
94
+ { prepend_rejected: true }
95
+ end
96
+
97
+ # @!method self.prune_list(list, rejected, parameters)
98
+ # Prune all objects that do not respond to a given array of parameters.
99
+ #
100
+ # @private
101
+ # @!scope class
102
+ # @!visibility private
103
+ #
104
+ # @param [Array<Object>] list the 'list' of objects we are pruning from.
105
+ # @param [Array<Object>] rejected the objects we have pruned from list.
106
+ # @param [Array<Symbol>] parameters an array of parameters we are checking.
107
+ #
108
+ # @return [Array<Array<Object>, Array<Object>>] an array containing first, the pruned list and secondly, the rejected list.
109
+ private_class_method def self.prune_list(list, rejected, parameters)
110
+ list.delete_if do |object|
111
+ rejected << object unless parameters.all? { |param| !object.send(param).nil? if object.respond_to?(param) }
112
+ end
113
+
114
+ [list, rejected]
115
+ end
116
+
117
+ # @!method self.sort_list(list, parameters)
118
+ # Sort a given list of objects by a list of parameters.
119
+ #
120
+ # @private
121
+ # @!scope class
122
+ # @!visibility private
123
+ #
124
+ # @param [Array<Object>] list the 'list' of objects we are pruning from.
125
+ # @param [Array<Symbol>] parameters an array of parameters we are checking.
126
+ #
127
+ # @return [Array<Object>] our sorted list.
128
+ private_class_method def self.sort_list(list, parameters)
129
+ list.sort_by! do |object|
130
+ parameters.map do |param|
131
+ object.send(param).is_a?(String) ? I18n.transliterate(object.send(param)).downcase : object.send(param)
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,5 @@
1
+ module Parliament
2
+ module NTriple
3
+ VERSION = '0.0.1.pre'.freeze
4
+ end
5
+ end
@@ -0,0 +1,139 @@
1
+ require 'forwardable'
2
+
3
+ module Parliament
4
+ module Response
5
+ # N-Triple response object that wraps an Array of Grom::Node objects with common helper methods.
6
+ #
7
+ # Delegates a number of common methods to the array of Grom::Nodes including, but not limited to, :size, :each, :map, :count etc.
8
+ #
9
+ # @since 0.1.0
10
+ #
11
+ # @see Parliament::Response::BaseReponse#initialize
12
+ #
13
+ # @attr_reader [Array<Grom::Node>] nodes Graph nodes.
14
+ class NTripleResponse < Parliament::Response::BaseResponse
15
+ include Enumerable
16
+ extend Forwardable
17
+ attr_reader :nodes
18
+ def_delegators :@nodes, :size, :each, :select, :map, :select!, :map!, :count, :length, :[], :empty?
19
+
20
+ # @param [Array<Grom::Node>] nodes An array of nodes the response should wrap
21
+ def initialize(nodes)
22
+ @nodes = nodes
23
+ end
24
+
25
+ # Given our array of Grom::Nodes, filter them into arrays of 'types' of nodes.
26
+ #
27
+ # Note: this method assumes all of your nodes include a #type attribute or are blank nodes.
28
+ #
29
+ # @since 0.2.0
30
+ #
31
+ # @example Filtering for a single type
32
+ # node_1 = Grom::Node.new
33
+ # node_1.instance_variable_set(:type, 'type_1')
34
+ # node_2 = Grom::Node.new
35
+ # node_2.instance_variable_set(:type, 'type_3')
36
+ # node_3 = Grom::Node.new
37
+ # node_3.instance_variable_set(:type, 'type_1')
38
+ # node_4 = Grom::Node.new
39
+ # node_4.instance_variable_set(:type, 'type_2')
40
+ # nodes = [node_1, node_2, node_3, node_4]
41
+ #
42
+ # response = Parliament::Response::NTriple.new(nodes)
43
+ # response.filter('type_2') #=> [#<Grom::Node @type='type_2'>]
44
+ #
45
+ # @example Filtering for multiple types
46
+ # node_1 = Grom::Node.new
47
+ # node_1.instance_variable_set(:type, 'type_1')
48
+ # node_2 = Grom::Node.new
49
+ # node_2.instance_variable_set(:type, 'type_3')
50
+ # node_3 = Grom::Node.new
51
+ # node_3.instance_variable_set(:type, 'type_1')
52
+ # node_4 = Grom::Node.new
53
+ # node_4.instance_variable_set(:type, 'type_2')
54
+ # nodes = [node_1, node_2, node_3, node_4]
55
+ #
56
+ # response = Parliament::Response::NTripleResponse.new(nodes)
57
+ # response.filter('type_2', 'type_1') #=> [[#<Grom::Node @type='type_2'>], [#<Grom::Node @type='type_1'>, #<Grom::Node @type='type_1'>]]
58
+ #
59
+ # # Also consider
60
+ # type_2, type_1 = response.filter('type_2', 'type_1')
61
+ # type_2 #=> [#<Grom::Node @type='type_2'>]
62
+ # type_1 #=> [#<Grom::Node @type='type_1'>, #<Grom::Node @type='type_1'>]
63
+ #
64
+ # @example Filtering blank nodes
65
+ # node_1 = Grom::Node.new
66
+ # node_1.instance_variable_set(:type, 'type_1')
67
+ # node_2 = Grom::Node.new
68
+ # node_3 = Grom::Node.new
69
+ # node_3.instance_variable_set(:type, 'type_1')
70
+ # nodes = [node_1, node_2, node_3]
71
+ #
72
+ # response = Parliament::Response::NTripleResponse.new(nodes)
73
+ # response.filter(Grom::Node::BLANK) #=> [#<Grom::Node>]
74
+ #
75
+ # @param [Array<String>] types An array of type strings that you are looking for.
76
+ # @return [Array<Grom::Node> || Array<*Array<Grom::Node>>] If you pass one type, this returns an Array of Grom::Node objects. If you pass multiple, it returns an array, of arrays of Grom::Node objects.
77
+ def filter(*types)
78
+ filtered_objects = Array.new(types.size) { [] }
79
+
80
+ unless types.empty?
81
+ @nodes.each do |node|
82
+ type_index = node.blank? ? types.index(::Grom::Node::BLANK) : types.index(node.type)
83
+
84
+ filtered_objects[type_index] << node unless type_index.nil?
85
+ end
86
+ end
87
+
88
+ result = build_responses(filtered_objects)
89
+
90
+ types.size == 1 ? result.first : result
91
+ end
92
+
93
+ # Sort the Parliament::Response nodes in ascending order by a set of attributes on each node.
94
+ #
95
+ # @see Parliament::Utils.sort_by
96
+ #
97
+ # @since 0.5.0
98
+ #
99
+ # @param [Array<Symbol>] parameters Attributes to sort on - left to right.
100
+ # @return [Array<Grom::Node>] A sorted array of nodes.
101
+ def sort_by(*parameters)
102
+ Parliament::NTriple::Utils.sort_by(
103
+ {
104
+ list: @nodes,
105
+ parameters: parameters
106
+ }
107
+ )
108
+ end
109
+
110
+ # Sort the Parliament::Response nodes in descending order by a set of attributes on each node.
111
+ #
112
+ # @see Parliament::Utils.reverse_sort_by
113
+ #
114
+ # @since 0.5.0
115
+ #
116
+ # @param [Array<Symbol>] parameters Attributes to sort on - left to right.
117
+ # @return [Array<Grom::Node>] A sorted array of nodes.
118
+ def reverse_sort_by(*parameters)
119
+ Parliament::NTriple::Utils.reverse_sort_by(
120
+ {
121
+ list: @nodes,
122
+ parameters: parameters
123
+ }
124
+ )
125
+ end
126
+
127
+ private
128
+
129
+ def build_responses(filtered_objects)
130
+ result = []
131
+
132
+ filtered_objects.each do |objects|
133
+ result << Parliament::Response::NTripleResponse.new(objects)
134
+ end
135
+ result
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'parliament/ntriple/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'parliament-ntriple'
8
+ spec.version = Parliament::NTriple::VERSION
9
+ spec.authors = ['Rebecca Appleyard']
10
+ spec.email = ['rklappleyard@gmail.com']
11
+
12
+ spec.summary = %q{Parliamentary NTriple response builder}
13
+ spec.description = %q{Parliamentary NTriple response builder}
14
+ spec.homepage = 'http://github.com/ukparliament/parliament_ntriple'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ # spec.add_dependency 'parliament-ruby', '~> 0.7.4'
24
+
25
+ spec.add_dependency 'grom', '~> 0.3.6'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.14'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'rubocop', '~> 0.47'
31
+ spec.add_development_dependency 'simplecov', '~> 0.12'
32
+ spec.add_development_dependency 'vcr', '~> 3.0'
33
+ spec.add_development_dependency 'webmock', '~> 2.3'
34
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parliament-ntriple
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - Rebecca Appleyard
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grom
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.47'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.47'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.12'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.3'
125
+ description: Parliamentary NTriple response builder
126
+ email:
127
+ - rklappleyard@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".hound.yml"
134
+ - ".idea/vcs.xml"
135
+ - ".rspec"
136
+ - ".rubocop.yml"
137
+ - ".travis.yml"
138
+ - CODE_OF_CONDUCT.md
139
+ - Gemfile
140
+ - LICENSE
141
+ - README.md
142
+ - Rakefile
143
+ - bin/console
144
+ - bin/setup
145
+ - lib/parliament/builder/ntriple_response_builder.rb
146
+ - lib/parliament/ntriple.rb
147
+ - lib/parliament/ntriple/utils.rb
148
+ - lib/parliament/ntriple/version.rb
149
+ - lib/parliament/response/ntriple_response.rb
150
+ - parliament-ntriple.gemspec
151
+ homepage: http://github.com/ukparliament/parliament_ntriple
152
+ licenses: []
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">"
166
+ - !ruby/object:Gem::Version
167
+ version: 1.3.1
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.6.6
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Parliamentary NTriple response builder
174
+ test_files: []