rdf-kv 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: deb27dba84f5646d65c33ad83bd4ac842724ed0458f943194c572ef06b9ab679
4
- data.tar.gz: 150094cd1b73702b87ada062070d66752bab1c28be502aaad8ca754fa7d51815
3
+ metadata.gz: 8ace8319f10ea7f736fc8881d6546b19c908284189e5a40f1d0e08659bad5b19
4
+ data.tar.gz: f38dd9a9e778c037aad1199d6fc753bf6c037ba00acf0d6ee6e437e81efc0034
5
5
  SHA512:
6
- metadata.gz: 49fdd4acc90ca6089385473885b8fc49a9160e7d628eaf53242ab209f9b9858941d533df9966f7a77b853b20e4b203791ac43e58b566443ebab66e4196b18cfc
7
- data.tar.gz: 58f9571d7c07fadbe58ca1e171382ea0a00ed43e86b02236dbba8e496be078a9ec62b29b03ce2d927b6ac609817318320adfa52d0f0049c62755f463ee20fe83
6
+ metadata.gz: efc28fc50193b33e5b461e053eff1e2eed46da55e29dd569b0546b0ef606f05b71dc36430eefed20031b35c25d5a2f455edcebda07f7fe327de7d43cf9373a68
7
+ data.tar.gz: 053f381f9cf6d907183103f50e47ffd2e5a3f5f85c86b7017dfca0d7733b993cc5994e37feb4890183a8c9f3bbfe7dd5c63829fb9e0b39ccc63b25747c5bc3c4
data/.gitignore CHANGED
@@ -12,3 +12,4 @@ Gemfile.lock
12
12
  .rspec_status
13
13
  .\#*
14
14
  \#*\#
15
+ *.gem
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --output-dir doc/yard
2
+ --protected
3
+ --no-private
4
+ --hide-void-return
5
+ --markup markdown
6
+ --readme README.md
7
+ -
@@ -1,5 +1,5 @@
1
1
  module RDF
2
2
  class KV
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
data/lib/rdf/kv.rb CHANGED
@@ -35,7 +35,7 @@ class RDF::KV
35
35
 
36
36
  GRAMMAR = /#{PARTIAL_STMT}/o
37
37
  MAP = %i[modifier term1 term2 designator term1 designator graph
38
- term1 term2 designator graph deref]
38
+ term1 term2 designator graph deref].freeze
39
39
 
40
40
  # these should be instance_exec'd
41
41
  SPECIALS = {
@@ -47,10 +47,10 @@ class RDF::KV
47
47
  val.each do |v, _|
48
48
  next unless m = /^\s*(#{NCNAME}):\s+(.*)$/o.match(v)
49
49
  prefix, uri = m.captures
50
- @namespaces[prefix.to_sym] = RDF::Vocabulary.new uri
50
+ @prefixes[prefix.to_sym] = RDF::Vocabulary.new uri
51
51
  end
52
52
  },
53
- }
53
+ }.freeze
54
54
 
55
55
  # macros are initially represented as a pair: the macro value and a
56
56
  # flag denoting whether or not the macro itself contains macros and to
@@ -60,7 +60,7 @@ class RDF::KV
60
60
  NEW_UUID_URN: [[-> { UUIDTools::UUID.random_create.to_uri }, false]],
61
61
  NEW_BNODE: [[-> { "_:#{UUID::NCName.to_ncname_64(
62
62
  UUIDTools::UUID.random_create.to_s, version: 1) }" }, false]],
63
- }
63
+ }.freeze
64
64
 
65
65
  # just the classics
66
66
  DEFAULT_NS = {
@@ -70,15 +70,14 @@ class RDF::KV
70
70
  xsd: RDF::XSD,
71
71
  }.freeze
72
72
 
73
+ # Given a (massaged) set of macros, dereference the given array of
74
+ # strings and return it.
73
75
  def deref_content strings, macros
74
76
  strings = [strings] unless strings.is_a? Array
75
77
  # bail out early if there is nothing to do
76
78
  return strings unless strings.any? { |s| /#{MACRO}/o.match s }
77
79
  out = []
78
80
  strings.each do |s|
79
- # sometimes these are arrays of arrays
80
- #s = s.first if s.is_a? Array
81
-
82
81
  # chunks are parallel output; each element is a value
83
82
  chunks = []
84
83
  s.scan(/\G#{MACROS}/o) do |m|
@@ -125,6 +124,10 @@ class RDF::KV
125
124
  out
126
125
  end
127
126
 
127
+ # Given the structure of macro declarations, dereference any
128
+ # recursively-defined macros, and return a new structure with a key
129
+ # and array of _values_, rather than an array of `[value, deref]`
130
+ # pairs.
128
131
  def massage_macros macros
129
132
  seen = {}
130
133
  done = GENERATED.transform_values { |v| v.map { |w| w.first } }
@@ -147,9 +150,7 @@ class RDF::KV
147
150
  next unless deref
148
151
 
149
152
  if deref.is_a? Array
150
- deref.each do |m|
151
- done[m] ? dm[m] = true : pm[m] = true
152
- end
153
+ deref.each { |m| done[m] ? dm[m] = true : pm[m] = true }
153
154
  else
154
155
  m = {}
155
156
  val.scan(/#{MACRO}/o).compact.each do |x|
@@ -161,7 +162,8 @@ class RDF::KV
161
162
 
162
163
  done[m] ? dm[m] = true : pm[m] = true
163
164
  end
164
- # push the deref
165
+
166
+ # replace the deref flag with the elements to deref with
165
167
  pair[1] = m.empty? ? false : m.keys.sort
166
168
  end
167
169
  end
@@ -174,6 +176,7 @@ class RDF::KV
174
176
  q << m
175
177
  end
176
178
 
179
+ # put the current key back on the queue but put the dependencies first
177
180
  queue = q + [k] + queue
178
181
  next
179
182
  end
@@ -205,7 +208,7 @@ class RDF::KV
205
208
  # ugh now we gotta do urls
206
209
  if m = /^(#{NCNAME}):(\S*)$/o.match(term)
207
210
  prefix, slug = m.captures
208
- if !slug.start_with?(?/) and vocab = namespaces[prefix.to_sym]
211
+ if !slug.start_with?(?/) and vocab = prefixes[prefix.to_sym]
209
212
  return vocab[slug]
210
213
  end
211
214
  end
@@ -238,37 +241,39 @@ class RDF::KV
238
241
 
239
242
  # call the callback if we have one
240
243
  term = callback.call term if callback
241
-
244
+
242
245
  term
243
246
  end
244
247
 
245
248
  public
246
249
 
247
- attr_reader :subject, :graph, :namespaces, :callback
250
+ attr_reader :subject, :graph, :prefixes, :callback
251
+ # why is this :target, :source
252
+ alias_method :namespaces, :prefixes
248
253
 
249
254
  # Initialize the processor.
250
255
  #
251
- # @param subject [RDF::URI] The default subject. Required.
252
- # @param graph [RDF::URI] The default context. Optional.
253
- # @param namespaces [Hash] Namespace/prefix mappings. Optional.
254
- # @param callback [#call] A callback that expects and returns a term.
256
+ # @param subject [RDF::URI] The default subject. Required.
257
+ # @param graph [RDF::URI] The default context. Optional.
258
+ # @param prefixes [Hash] Namespace/prefix mappings. Optional.
259
+ # @param callback [#call] A callback that expects and returns a term.
255
260
  # Optional.
256
261
  #
257
- def initialize subject: nil, graph: nil, namespaces: {}, callback: nil
262
+ def initialize subject: nil, graph: nil, prefixes: {}, callback: nil
258
263
  # look at all of our pretty assertions
259
264
  raise ArgumentError, 'subject must be an RDF::Resource' unless
260
265
  subject.is_a? RDF::Resource
261
266
  raise ArgumentError, 'graph must be an RDF::Resource' unless
262
267
  graph.nil? or graph.is_a? RDF::Resource
263
- raise ArgumentError, 'namespaces must be hashable' unless
264
- namespaces.respond_to? :to_h
268
+ raise ArgumentError, 'prefixes must be hashable' unless
269
+ prefixes.respond_to? :to_h
265
270
  rase ArgumentError, 'callback must be callable' unless
266
271
  callback.nil? or callback.respond_to? :call
267
272
 
268
- @subject = subject
269
- @graph = graph
270
- @callback = callback
271
- @namespaces = DEFAULT_NS.merge(namespaces.to_h.map do |k, v|
273
+ @subject = subject
274
+ @graph = graph
275
+ @callback = callback
276
+ @prefixes = DEFAULT_NS.merge(prefixes.to_h.map do |k, v|
272
277
  k = k.to_s.to_sym unless k.is_a? Symbol
273
278
  # coerce to uri
274
279
  v = RDF::URI(v.to_s) unless v.is_a? RDF::Resource
@@ -327,7 +332,7 @@ class RDF::KV
327
332
  end
328
333
  rescue Exception => e
329
334
  # again this should be nicer
330
- raise e
335
+ raise Error.new e
331
336
  end
332
337
 
333
338
  # this will be our output
@@ -418,4 +423,6 @@ class RDF::KV
418
423
 
419
424
  patch
420
425
  end
426
+
427
+ class Error < RuntimeError; end
421
428
  end
data/lib/rdf-kv.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rdf/kv'
data/rdf-kv.gemspec CHANGED
@@ -29,16 +29,16 @@ RDF::Changeset.
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
31
 
32
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
32
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7')
33
33
  # dev/test dependencies
34
34
  spec.add_development_dependency 'bundler', '~> 2'
35
- spec.add_development_dependency 'rdf-vocab', '~> 3.1'
35
+ spec.add_development_dependency 'rdf-vocab', '~> 3'
36
36
 
37
37
  # stuff we use
38
- spec.add_runtime_dependency 'rdf', '>= 3.1.1' # include my changes
38
+ spec.add_runtime_dependency 'rdf', '~> 3' # include my changes
39
39
  spec.add_runtime_dependency 'uuidtools', '~> 2'
40
40
 
41
41
  # stuff i wrote
42
- spec.add_runtime_dependency 'uuid-ncname', '>= 0.2.5'
42
+ spec.add_runtime_dependency 'uuid-ncname', '>= 0.4'
43
43
 
44
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-kv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Taylor
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-09 00:00:00.000000000 Z
11
+ date: 2024-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.1'
33
+ version: '3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.1'
40
+ version: '3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdf
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.1.1
47
+ version: '3'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.1.1
54
+ version: '3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: uuidtools
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.2.5
75
+ version: '0.4'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 0.2.5
82
+ version: '0.4'
83
83
  description: |
84
84
  This module implements https://doriantaylor.com/rdf-kv, taking
85
85
  key-value input (e.g. from a Web form) and converting it into an
@@ -93,12 +93,14 @@ files:
93
93
  - ".gitignore"
94
94
  - ".rspec"
95
95
  - ".travis.yml"
96
+ - ".yardopts"
96
97
  - Gemfile
97
98
  - LICENSE
98
99
  - README.md
99
100
  - Rakefile
100
101
  - bin/console
101
102
  - bin/setup
103
+ - lib/rdf-kv.rb
102
104
  - lib/rdf/kv.rb
103
105
  - lib/rdf/kv/version.rb
104
106
  - rdf-kv.gemspec
@@ -107,7 +109,7 @@ licenses:
107
109
  - Apache-2.0
108
110
  metadata:
109
111
  homepage_uri: https://github.com/doriantaylor/rb-rdf-kv
110
- post_install_message:
112
+ post_install_message:
111
113
  rdoc_options: []
112
114
  require_paths:
113
115
  - lib
@@ -115,15 +117,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
117
  requirements:
116
118
  - - ">="
117
119
  - !ruby/object:Gem::Version
118
- version: 2.3.0
120
+ version: '2.7'
119
121
  required_rubygems_version: !ruby/object:Gem::Requirement
120
122
  requirements:
121
123
  - - ">="
122
124
  - !ruby/object:Gem::Version
123
125
  version: '0'
124
126
  requirements: []
125
- rubygems_version: 3.1.2
126
- signing_key:
127
+ rubygems_version: 3.3.15
128
+ signing_key:
127
129
  specification_version: 4
128
130
  summary: Ruby implementation of the RDF-KV protocol
129
131
  test_files: []