ldpath 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d28ccab2d84a4940b22d84fb600e064502c13e66
4
- data.tar.gz: df43a5b99ec5247b4dfe47a6cb13a9d8ce2049ba
3
+ metadata.gz: 214f447c642fd8d87b794962987dc6ab57112c08
4
+ data.tar.gz: 4b0a6a855fae1a2532e9f081d9e8c17f52da8974
5
5
  SHA512:
6
- metadata.gz: da380d1b4292306f3465036491ecb03ce233bf4b14620e0a3ad9ceeddc37628c78c67acebb1061f5c1ac5ce4a591c4c00e7b2fe791bb32189d45c1c8888def06
7
- data.tar.gz: 3a37f12008af97a7acd1cacf11d469efe5d6825f902b6d00927264a0a49bad51ae34412ef17e393b702cc649f192ab1bdc3004c728adc3b6c5c2fa673530c8c6
6
+ metadata.gz: 12447d394cf8c3ee69b7835246a58b5a71d1a53dd088d97c52c1557baeb67061b9ef35b79538572883a10cca84e1795497aaea91330823ac280b6002eb59245f
7
+ data.tar.gz: 8e0fb7e040b1e3163bde5558fa51fc669e5cf8e3f03f0ceffbba20ca831b961d9a3e5ef349e62eb5da2f80187a102120a9e9863fb4734d9193e3b769b3a04e45
data/.rubocop.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  inherit_from:
2
- - .rubocop_hound.yml
3
2
  - .rubocop_todo.yml
4
3
 
5
- AllCops:
6
- Exclude:
7
- - "*.gemspec"
4
+ Metrics/LineLength:
5
+ Max: 140
6
+
7
+ Style/WordArray:
8
+ Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,36 +1,5 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-05-03 18:22:33 -0700 using RuboCop version 0.30.0.
3
- # The point is for the user to remove these configuration records
4
- # one by one as the offenses are removed from the code base.
5
- # Note that changes in the inspected code, or installation of new
6
- # versions of RuboCop, may require this file to be generated again.
7
-
8
- # Offense count: 1
9
- # Cop supports --auto-correct.
10
- Lint/UnusedBlockArgument:
11
- Enabled: false
12
-
13
- # Offense count: 68
14
- # Cop supports --auto-correct.
15
- Lint/UnusedMethodArgument:
16
- Enabled: false
17
-
18
- # Offense count: 4
19
- Metrics/AbcSize:
20
- Max: 28
21
-
22
- # Offense count: 47
23
- # Configuration parameters: AllowURI, URISchemes.
24
- Metrics/LineLength:
25
- Max: 171
26
-
27
- # Offense count: 7
28
- # Cop supports --auto-correct.
29
- Style/ExtraSpacing:
1
+ Style/StringLiterals:
30
2
  Enabled: false
31
3
 
32
- # Offense count: 42
33
- # Cop supports --auto-correct.
34
- # Configuration parameters: EnforcedStyle, SupportedStyles.
35
- Style/StringLiterals:
4
+ Style/Documentation:
36
5
  Enabled: false
data/.travis.yml CHANGED
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.1
3
+ - 2.4.5
4
+ - 2.5.3
5
+ before_install:
6
+ - gem update --system
data/CHANGELOG.md ADDED
@@ -0,0 +1,98 @@
1
+ ### 1.0.0 (2019-03-29)
2
+
3
+ * add ability to restrict results to passed in context
4
+ * Add Coveralls for test coverage analysis
5
+ * update to make all tests pass
6
+ * move to samvera-labs
7
+ * Refactor recursive path selector
8
+ * Extract Result#evaluate to FieldMapping#evaluate
9
+ * Defer mapping enumerables to arrays until Result#to_hash
10
+ * Remove hound's rubocop styling and replace with default upstream styles
11
+ * Convert selectors to yield enumerators instead of arrays
12
+ * Extract Ldpath::Result from Ldpath::Program
13
+ * Update travis build matrix
14
+ * Update to rdf 2.x
15
+ * Refactor grouping rule into a macro
16
+ * Refactor and/or tests to use left and right operands
17
+ * Refactor transforms to remove case statements within rules
18
+ * Add the range \u10000 - \uEFFFF to the allowed prefix chars
19
+ * Add simplecov
20
+ * Add NegatedPropertySelector from sparql property paths
21
+ * Add reasonable error handling to the ldpath binary
22
+
23
+ ### 0.3.1 (2015-05-04)
24
+
25
+ * Add reasonable error handling to parsing the user input
26
+
27
+ ### 0.3.0 (2015-05-04)
28
+
29
+ * push literal parsing down to literal
30
+ * map strings to strings
31
+ * Parse literals into properly typed and lang-tagged literals
32
+
33
+ ### 0.2.0 (2015-05-03)
34
+
35
+ * Use rubocop to enforce a common style
36
+ * refactor parser rules
37
+ * Improve transform specs
38
+ * Add 'zero or one' path operator
39
+ * refactor recursive_path_selector
40
+ * refactoring parsing for compound selectors
41
+ * Add support for single line, sparql-style comments
42
+ * Use sparql's definition of the prefix identifier
43
+ * Adopt turtle's EBNF names for basic types
44
+ * require that the prologue occur before the mappings
45
+ * add parsing spec
46
+ * Use parse, not parse_with_debug
47
+ * Simplify the ldpath parser
48
+ * Add list-aware functions
49
+
50
+ ### 0.1.0 (2015-04-04)
51
+
52
+ * Add bin/ldpath
53
+ * Update gem homepage
54
+ * Support parsing the field type options
55
+ * Parse and ignore @boost
56
+ * Support @filter
57
+ * Add more lenient whitespace parsing
58
+ * Add fn:xpath
59
+ * Complete test functions (fn:eq, fn:ne, etc)
60
+
61
+ ### 0.0.2 (2015-04-02)
62
+
63
+ * Fix and test ldpath functions receiving selectors
64
+ * Load rdf/reasoner as a dev dependency
65
+ * Always attempt retrieve resources unless they've been previously fetched
66
+ * Add loose property selector (~) for allowing super-properties to be u…
67
+ * Add debug logging when loading resources
68
+ * Add tap selector for saving additional metadata while evaluating a ma…
69
+ * Use RDF::Util::Cache by default to cache retrieved graphs
70
+ * Add fn:predicates function for retrieving available predicates for an…
71
+
72
+ ### 0.0.1 (2014-07-21)
73
+
74
+ * Update README.md
75
+ * Add is and is-a tests
76
+ * Add add/or/not tests
77
+ * Add type test
78
+ * Handle mapping fields to literals
79
+ * Allow strlits to include escaped quotes
80
+ * treat functions as a mixin to the program
81
+ * Update functions to support property arrays for certain arguments
82
+ * Naive stub implementations for functions
83
+ * Improve the parser tests
84
+ * Naively try to load up RDF graphs whenver they are referenced by URI
85
+ * Add field datatype declarations
86
+ * Extract Ldpath::Selector to handle the default wrapping/unwrapping
87
+ * Add convenient accessor to parse and evaluate a program
88
+ * Reorganize Ldpath::Transform
89
+ * Re-organize the Ldpath::Parser rules
90
+ * Anywhere there's whitespace is (probably) a valid place for a multili…
91
+ * Implement partial testing selectors
92
+ * Add recursive path selector
93
+ * Implement low-hanging selectors
94
+ * add README
95
+ * Implement path selector evaluation
96
+ * Demonstrate evaluating an LDPath program with a simple property selector
97
+ * first pass at transforming the parslet output into an AST
98
+ * initial commit
@@ -0,0 +1,36 @@
1
+ The Samvera community is dedicated to providing a welcoming and
2
+ positive experience for all its members, whether they are at a formal
3
+ gathering, in a social setting, or taking part in activities online.
4
+ The Samvera community welcomes participation from people all over the
5
+ world and these members bring with them a wide variety of
6
+ professional, personal and social backgrounds; whatever these may be,
7
+ we treat colleagues with dignity and respect.
8
+
9
+ Community members communicate primarily in English, though for many of
10
+ them this is not their native language. We therefore strive to express
11
+ ourselves simply and clearly remembering that unnecessary use of
12
+ jargon and slang will be a barrier to understanding for many of our
13
+ colleagues. We are sensitive to the fact that the international
14
+ nature of the community means that we span many different social norms
15
+ around language and behaviour and we strive to conduct ourselves,
16
+ online and in person, in ways that are unlikely to cause offence.
17
+
18
+ Samvera conversations are often information-rich and intended to
19
+ generate discussion and debate. We discuss ideas from a standpoint of
20
+ mutual respect and reasoned argument.
21
+
22
+ Community members work together to promote a respectful and safe
23
+ community. In the event that someone’s conduct is causing offence or
24
+ distress, Samvera has a detailed
25
+ [Anti-Harassment Policy and Protocol](https://wiki.duraspace.org/display/samvera/Anti-Harassment+Policy)
26
+ which can be applied to address the problem. The first step in dealing
27
+ with any serious misconduct is to contact a local meeting organizer,
28
+ the
29
+ [Samvera community helpers](https://wiki.duraspace.org/display/samvera/Samvera+Community+Helpers)
30
+ ([email](mailto:helpers@samvera.org)), a community member you
31
+ trust, or the
32
+ [Samvera Steering Group](https://wiki.duraspace.org/display/samvera/Samvera+Steering+Group+membership)
33
+ immediately; at Samvera events, these people can be identified by
34
+ distinctive name badges. The
35
+ [Policy and Protocol](https://wiki.duraspace.org/display/samvera/Anti-Harassment+Policy)
36
+ should be consulted for fuller details.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,161 @@
1
+ # How to Contribute
2
+
3
+ We want your help to make the Samvera community great. There are a few guidelines
4
+ that we need contributors to follow so that we can have a chance of
5
+ keeping on top of things.
6
+
7
+ ## Code of Conduct
8
+
9
+ The Samvera Community is dedicated to providing a welcoming and positive
10
+ experience for all its members, whether they are at a formal gathering, in
11
+ a social setting, or taking part in activities online. Please see our
12
+ [Code of Conduct](CODE_OF_CONDUCT.md) for more information.
13
+
14
+ ## Samvera Community Intellectual Property Licensing and Ownership
15
+
16
+ All code contributors must have an Individual Contributor License Agreement
17
+ (iCLA) on file with the Samvera Steering Group. If the contributor works for
18
+ an institution, the institution must have a Corporate Contributor License
19
+ Agreement (cCLA) on file.
20
+
21
+ https://wiki.duraspace.org/display/samvera/Samvera+Community+Intellectual+Property+Licensing+and+Ownership
22
+
23
+ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the project.
24
+
25
+ ## Contribution Tasks
26
+
27
+ * Reporting Issues
28
+ * Making Changes
29
+ * Documenting Code
30
+ * Committing Changes
31
+ * Submitting Changes
32
+ * Reviewing and Merging Changes
33
+
34
+ ### Reporting Issues
35
+
36
+ * Make sure you have a [GitHub account](https://github.com/signup/free)
37
+ * Submit a [Github issue](https://github.com/samvera/questioning_authority/issues) by:
38
+ * Clearly describing the issue
39
+ * Provide a descriptive summary
40
+ * Explain the expected behavior
41
+ * Explain the actual behavior
42
+ * Provide steps to reproduce the actual behavior
43
+
44
+ ### Making Changes
45
+
46
+ * Fork the repository on GitHub
47
+ * Create a topic branch from where you want to base your work.
48
+ * This is usually the master branch.
49
+ * To quickly create a topic branch based on master; `git branch fix/master/my_contribution master`
50
+ * Then checkout the new branch with `git checkout fix/master/my_contribution`.
51
+ * Please avoid working directly on the `master` branch.
52
+ * You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful
53
+ * Make sure you have added sufficient tests and documentation for your changes.
54
+ * Test functionality with RSpec; Test features / UI with Capybara.
55
+ * Run _all_ the tests to assure nothing else was accidentally broken.
56
+
57
+ ### Documenting Code
58
+
59
+ * All new public methods, modules, and classes should include inline documentation in [YARD](http://yardoc.org/).
60
+ * Documentation should seek to answer the question "why does this code exist?"
61
+ * Document private / protected methods as desired.
62
+ * If you are working in a file with no prior documentation, do try to document as you gain understanding of the code.
63
+ * If you don't know exactly what a bit of code does, it is extra likely that it needs to be documented. Take a stab at it and ask for feedback in your pull request. You can use the 'blame' button on GitHub to identify the original developer of the code and @mention them in your comment.
64
+ * This work greatly increases the usability of the code base and supports the on-ramping of new committers.
65
+ * We will all be understanding of one another's time constraints in this area.
66
+ * [Getting started with YARD](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
67
+
68
+ ### Committing changes
69
+
70
+ * Make commits of logical units.
71
+ * Check for unnecessary whitespace with `git diff --check` before committing.
72
+ * Make sure your commit messages are [well formed](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
73
+ * If you created an issue, you can close it by including "Closes #issue" in your commit message. See [Github's blog post for more details](https://github.com/blog/1386-closing-issues-via-commit-messages)
74
+
75
+ ```
76
+ Present tense short summary (50 characters or less)
77
+
78
+ More detailed description, if necessary. It should be wrapped to 72
79
+ characters. Try to be as descriptive as you can, even if you think that
80
+ the commit content is obvious, it may not be obvious to others. You
81
+ should add such description also if it's already present in bug tracker,
82
+ it should not be necessary to visit a webpage to check the history.
83
+
84
+ Include Closes #<issue-number> when relavent.
85
+
86
+ Description can have multiple paragraphs and you can use code examples
87
+ inside, just indent it with 4 spaces:
88
+
89
+ class PostsController
90
+ def index
91
+ respond_to do |wants|
92
+ wants.html { render 'index' }
93
+ end
94
+ end
95
+ end
96
+
97
+ You can also add bullet points:
98
+
99
+ - you can use dashes or asterisks
100
+
101
+ - also, try to indent next line of a point for readability, if it's too
102
+ long to fit in 72 characters
103
+ ```
104
+
105
+ * Make sure you have added the necessary tests for your changes.
106
+ * Run _all_ the tests to assure nothing else was accidentally broken.
107
+ * When you are ready to submit a pull request
108
+
109
+ ### Submitting Changes
110
+
111
+ * Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
112
+ * Make sure your branch is up to date with its parent branch (i.e. master)
113
+ * `git checkout master`
114
+ * `git pull --rebase`
115
+ * `git checkout <your-branch>`
116
+ * `git rebase master`
117
+ * It is a good idea to run your tests again.
118
+ * If you've made more than one commit take a moment to consider whether squashing commits together would help improve their logical grouping.
119
+ * [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
120
+ * `git rebase --interactive master` ([See Github help](https://help.github.com/articles/interactive-rebase))
121
+ * Squashing your branch's changes into one commit is "good form" and helps the person merging your request to see everything that is going on.
122
+ * Push your changes to a topic branch in your fork of the repository.
123
+ * Submit a pull request from your fork to the project.
124
+
125
+ ### Reviewing and Merging Changes
126
+
127
+ We adopted [Github's Pull Request Review](https://help.github.com/articles/about-pull-request-reviews/) for our repositories.
128
+ Common checks that may occur in our repositories:
129
+
130
+ 1. Travis CI - where our automated tests are running
131
+ 2. Approval Required - Github enforces at least one person approve a pull request. Also, all reviewers that have chimed in must approve.
132
+
133
+ If one or more of the required checks failed (or are incomplete), the code should not be merged (and the UI will not allow it). If all of the checks have passed, then anyone on the project (including the pull request submitter) may merge the code.
134
+
135
+ *Example: Carolyn submits a pull request, Justin reviews the pull request and approves. However, Justin is still waiting on other checks (Travis CI is usually the culprit), so he does not merge the pull request. Eventually, all of the checks pass. At this point, Carolyn or anyone else may merge the pull request.*
136
+
137
+ #### Things to Consider When Reviewing
138
+
139
+ First, the person contributing the code is putting themselves out there. Be mindful of what you say in a review.
140
+
141
+ * Ask clarifying questions
142
+ * State your understanding and expectations
143
+ * Provide example code or alternate solutions, and explain why
144
+
145
+ This is your chance for a mentoring moment of another developer. Take time to give an honest and thorough review of what has changed. Things to consider:
146
+
147
+ * Does the commit message explain what is going on?
148
+ * Does the code changes have tests? _Not all changes need new tests, some changes are refactorings_
149
+ * Do new or changed methods, modules, and classes have documentation?
150
+ * Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
151
+ * Does the description of the new/changed specs match your understanding of what the spec is doing?
152
+ * Did the Travis tests complete successfully?
153
+
154
+ If you are uncertain, bring other contributors into the conversation by assigning them as a reviewer.
155
+
156
+ # Additional Resources
157
+
158
+ * [General GitHub documentation](http://help.github.com/)
159
+ * [GitHub pull request documentation](https://help.github.com/articles/about-pull-requests/)
160
+ * [Pro Git](http://git-scm.com/book) is both a free and excellent book about Git.
161
+ * [A Git Config for Contributing](http://ndlib.github.io/practices/my-typical-per-project-git-config/)
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in ldpath.gemspec
4
- gemspec
3
+ gemspec path: File.expand_path('..', __FILE__)
4
+
5
+ group :development, :test do
6
+ gem 'coveralls', require: false
7
+ gem 'simplecov', require: false
8
+ end
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  This is a ruby implementation of [LDPath](http://marmotta.apache.org/ldpath/language.html), a language for selecting values linked data resources.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/ldpath.png)](http://badge.fury.io/rb/ldpath)
6
+ [![Build Status](https://travis-ci.org/samvera-labs/ldpath.png?branch=master)](https://travis-ci.org/samvera-labs/ldpath)
7
+ [![Coverage Status](https://coveralls.io/repos/github/samvera-labs/ldpath/badge.svg?branch=master)](https://coveralls.io/github/samvera-labs/ldpath?branch=master)
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -28,17 +32,37 @@ EOF
28
32
 
29
33
  uri = RDF::URI.new "info:a"
30
34
 
31
- context = RDF::Graph.new << [uri, RDF::DC.title, "Some Title"]
35
+ context = RDF::Graph.new << [uri, RDF::Vocab::DC.title, "Some Title"]
32
36
 
33
37
  program = Ldpath::Program.parse my_program
34
38
  output = program.evaluate uri, context
35
39
  # => { ... }
36
40
  ```
37
41
 
38
- ## Contributing
42
+ ## Compatibility
43
+
44
+ * Ruby 2.5 or the latest 2.4 version is recommended. Later versions may also work.
45
+
46
+ ## Product Owner & Maintenance
47
+
48
+ LDPath is moving toward being a Core Component of the Samvera community. The documentation for
49
+ what this means can be found [here](http://samvera.github.io/core_components.html#requirements-for-a-core-component).
50
+
51
+ ### Product Owner
52
+
53
+ [elrayle](https://github.com/elrayle)
54
+
55
+ # Help
56
+
57
+ The Samvera community is here to help. Please see our [support guide](./SUPPORT.md).
58
+
59
+ # Acknowledgments
60
+
61
+ This software has been developed by and is brought to you by the Samvera community. Learn more at the
62
+ [Samvera website](http://samvera.org/).
63
+
64
+ ![Samvera Logo](https://wiki.duraspace.org/download/thumbnails/87459292/samvera-fall-font2-200w.png?version=1&modificationDate=1498550535816&api=v2)
65
+
66
+ ### Special thanks to...
39
67
 
40
- 1. Fork it ( http://github.com/cbeer/ldpath.rb/fork )
41
- 2. Create your feature branch (`git checkout -b my-new-feature`)
42
- 3. Commit your changes (`git commit -am 'Add some feature'`)
43
- 4. Push to the branch (`git push origin my-new-feature`)
44
- 5. Create new Pull Request
68
+ [Chris Beer](https://github.com/cbeer) for the initial implementation of this gem!
data/SUPPORT.md ADDED
@@ -0,0 +1,6 @@
1
+ If you would like to report an issue, first search [the list of issues](https://github.com/samvera/questioning_authority/issues/) to see if someone else has already reported it, and then feel free to [create a new issue](https://github.com/samvera/questioning_authority/issues/new).
2
+
3
+ If you have questions or need help, please email [the Samvera community tech list](https://groups.google.com/forum/#!forum/samvera-tech) or stop by the #dev channel in [the Samvera community Slack team](https://wiki.duraspace.org/pages/viewpage.action?pageId=87460391#Getintouch!-Slack).
4
+
5
+ You can learn more about the various Samvera communication channels on the [Get in touch!](https://wiki.duraspace.org/pages/viewpage.action?pageId=87460391) wiki page.
6
+
data/bin/ldpath CHANGED
@@ -3,28 +3,36 @@
3
3
  require 'optparse'
4
4
  require 'open-uri'
5
5
  require 'ldpath'
6
- require 'byebug'
7
6
 
8
7
  begin
9
8
  require 'rest-client'
10
- rescue LoadError
9
+ rescue LoadError
11
10
  end
12
11
 
13
12
  options = {}
14
- OptionParser.new do |opts|
13
+ opt_parser = OptionParser.new do |opts|
15
14
  opts.banner = "Usage: ldpath [options] URI"
16
15
 
17
- opts.on("--program=STRING_URI_OR_FILE", "LDPath program to run (- for STDIN)") do |program|
18
- if File.exists?(program) || program =~ /^http/
19
- options[:program] = open(program).read
20
- elsif program.strip == "-"
21
- options[:program] = $stdin.read
22
- else
23
- options[:program] = program
24
- end
16
+ opts.on("--program=STRING_URI_OR_FILE", "LDPath program to run (reads from STDIN by default)") do |program|
17
+ options[:program] = if File.exist?(program) || program =~ /^http/
18
+ open(program).read
19
+ elsif program.strip == "-"
20
+ $stdin.read
21
+ else
22
+ program
23
+ end
25
24
  end
26
- end.parse!
25
+ end
26
+
27
+ opt_parser.parse!
27
28
 
28
29
  uri = ARGV.shift
29
30
 
31
+ if uri.nil?
32
+ $stderr.puts opt_parser
33
+ raise OptionParser::MissingArgument, "URI" unless uri
34
+ end
35
+
36
+ options[:program] ||= $stdin.read
37
+
30
38
  puts Ldpath::Program.parse(options[:program]).evaluate(RDF::URI.new(uri)).to_json
data/ldpath.gemspec CHANGED
@@ -8,20 +8,25 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Ldpath::VERSION
9
9
  spec.authors = ["Chris Beer"]
10
10
  spec.email = ["cabeer@stanford.edu"]
11
- spec.summary = %q{Ruby implementation of LDPath}
12
- spec.homepage = "https://github.com/cbeer/ldpath.rb"
11
+ spec.summary = "Ruby implementation of LDPath"
12
+ spec.homepage = "https://github.com/samvera-labs/ldpath"
13
13
  spec.license = "Apache 2"
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
-
19
+
20
20
  spec.add_dependency "parslet"
21
- spec.add_dependency "linkeddata"
21
+ spec.add_dependency "linkeddata", "~> 2.0"
22
22
 
23
+ # spec.add_development_dependency "bixby", "~> 1.0.0"
23
24
  spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "byebug"
24
26
  spec.add_development_dependency "rake"
25
27
  spec.add_development_dependency "rspec"
26
28
  spec.add_development_dependency "rdf-reasoner"
29
+ spec.add_development_dependency "simplecov"
30
+ spec.add_development_dependency "rubocop"
31
+ spec.add_development_dependency "webmock"
27
32
  end
@@ -1 +1,43 @@
1
- Ldpath::FieldMapping = Struct.new(:name, :selector, :field_type)
1
+ module Ldpath
2
+ class FieldMapping
3
+ attr_reader :name, :selector, :field_type
4
+
5
+ def initialize(name:, selector:, field_type: nil, options: {})
6
+ @name = name.to_s
7
+ @selector = selector
8
+ @field_type = field_type
9
+ @options = options
10
+ end
11
+
12
+ def evaluate(program, uri, context)
13
+ case selector
14
+ when Ldpath::Selector
15
+ return to_enum(:evaluate, program, uri, context) unless block_given?
16
+
17
+ selector.evaluate(program, uri, context).each do |value|
18
+ yield transform_value(value)
19
+ end
20
+ when RDF::Literal
21
+ Array(selector.canonicalize.object)
22
+ else
23
+ Array(selector)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def transform_value(value)
30
+ v = if value.is_a? RDF::Literal
31
+ value.canonicalize.object
32
+ else
33
+ value
34
+ end
35
+
36
+ if field_type
37
+ RDF::Literal.new(v.to_s, datatype: field_type).canonicalize.object
38
+ else
39
+ v
40
+ end
41
+ end
42
+ end
43
+ end