rdf 0.1.6.1 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6.1
1
+ 0.1.7
data/lib/rdf/format.rb CHANGED
@@ -109,7 +109,7 @@ module RDF
109
109
  else
110
110
  format = format.to_s.downcase
111
111
  @@subclasses.each do |klass|
112
- if klass.name.to_s.split('::').map(&:downcase).include?(format)
112
+ if klass.name.to_s.split('::').map { |x| x.downcase }.include?(format)
113
113
  return klass
114
114
  end
115
115
  end
@@ -146,7 +146,7 @@ module RDF
146
146
  # @see #each_triple
147
147
  # @see #enum_triple
148
148
  def triples(options = {})
149
- enum_statement.map(&:to_triple)
149
+ enum_statement.map { |statement| statement.to_triple }
150
150
  end
151
151
 
152
152
  ##
@@ -205,7 +205,7 @@ module RDF
205
205
  # @see #each_quad
206
206
  # @see #enum_quad
207
207
  def quads(options = {})
208
- enum_statement.map(&:to_quad)
208
+ enum_statement.map { |statement| statement.to_quad }
209
209
  end
210
210
 
211
211
  ##
@@ -267,7 +267,7 @@ module RDF
267
267
  # @see #enum_subject
268
268
  def subjects(options = {})
269
269
  if options[:unique] == false
270
- enum_statement.map(&:subject)
270
+ enum_statement.map { |statement| statement.subject }
271
271
  else
272
272
  enum_subject.to_a
273
273
  end
@@ -334,7 +334,7 @@ module RDF
334
334
  # @see #enum_predicate
335
335
  def predicates(options = {})
336
336
  if options[:unique] == false
337
- enum_statement.map(&:predicate)
337
+ enum_statement.map { |statement| statement.predicate }
338
338
  else
339
339
  enum_predicate.to_a
340
340
  end
@@ -401,7 +401,7 @@ module RDF
401
401
  # @see #enum_object
402
402
  def objects(options = {})
403
403
  if options[:unique] == false
404
- enum_statement.map(&:object)
404
+ enum_statement.map { |statement| statement.object }
405
405
  else
406
406
  enum_object.to_a
407
407
  end
@@ -468,7 +468,7 @@ module RDF
468
468
  # @see #enum_context
469
469
  def contexts(options = {})
470
470
  if options[:unique] == false
471
- enum_statement.map(&:context)
471
+ enum_statement.map { |statement| statement.context }
472
472
  else
473
473
  enum_context.to_a
474
474
  end
@@ -28,7 +28,7 @@ module RDF
28
28
  end
29
29
 
30
30
  ##
31
- # Loads RDF statements from the given file into `self`.
31
+ # Loads RDF statements from the given file or URL into `self`.
32
32
  #
33
33
  # @param [String, #to_s] filename
34
34
  # @param [Hash{Symbol => Object}] options
@@ -14,6 +14,36 @@ module RDF
14
14
  # @return [Array<Statement>]
15
15
  attr_accessor :data
16
16
 
17
+ ##
18
+ # Creates a new `Graph` instance populated by the RDF data returned by
19
+ # dereferencing the given context URL.
20
+ #
21
+ # @overload
22
+ # @param [String, #to_s] url
23
+ # @param [Hash{Symbol => Object}] options
24
+ # @yield [graph]
25
+ # @yieldparam [Graph] graph
26
+ # @return [void]
27
+ #
28
+ # @overload
29
+ # @param [String, #to_s] url
30
+ # @param [Hash{Symbol => Object}] options
31
+ # @return [Graph]
32
+ #
33
+ # @return [void]
34
+ def self.load(url, options = {}, &block)
35
+ self.new(url, options) do |graph|
36
+ graph.load! unless graph.unnamed?
37
+
38
+ if block_given?
39
+ case block.arity
40
+ when 1 then block.call(graph)
41
+ else graph.instance_eval(&block)
42
+ end
43
+ end
44
+ end
45
+ end
46
+
17
47
  ##
18
48
  # @param [Resource] context
19
49
  # @param [Hash{Symbol => Object}] options
@@ -26,8 +56,8 @@ module RDF
26
56
  else RDF::URI.new(context)
27
57
  end
28
58
 
29
- @data = options.delete(:data) || []
30
- @options = options
59
+ @options = options.dup
60
+ @data = @options.delete(:data) || []
31
61
 
32
62
  if block_given?
33
63
  case block.arity
@@ -37,6 +67,16 @@ module RDF
37
67
  end
38
68
  end
39
69
 
70
+ ##
71
+ # @return [void]
72
+ def load!(*args)
73
+ case
74
+ when args.empty?
75
+ load(context.to_s, context ? {:base_uri => context}.merge(@options) : @options)
76
+ else super
77
+ end
78
+ end
79
+
40
80
  ##
41
81
  # Returns `true` to indicate that this is a graph.
42
82
  #
@@ -79,6 +79,14 @@ module RDF
79
79
 
80
80
  alias_method :iri?, :uri?
81
81
 
82
+ ##
83
+ # Returns `true` if this value is a query variable.
84
+ #
85
+ # @return [Boolean]
86
+ def variable?
87
+ false
88
+ end
89
+
82
90
  ##
83
91
  # Compares this value to `other` for sorting purposes.
84
92
  #
@@ -108,7 +108,7 @@ class RDF::Query
108
108
  #
109
109
  # @return [Boolean]
110
110
  def bound?
111
- !variables.empty? && variables.values.all?(&:bound?)
111
+ !variables.empty? && variables.values.all? { |var| var.bound? }
112
112
  end
113
113
 
114
114
  ##
@@ -124,7 +124,7 @@ class RDF::Query
124
124
  #
125
125
  # @return [Boolean]
126
126
  def unbound?
127
- !variables.empty? && variables.values.all?(&:unbound?)
127
+ !variables.empty? && variables.values.all? { |var| var.unbound? }
128
128
  end
129
129
 
130
130
  ##
@@ -54,6 +54,15 @@ class RDF::Query
54
54
  @name, @value = name.to_sym, value
55
55
  end
56
56
 
57
+ ##
58
+ # Returns `true`.
59
+ #
60
+ # @return [Boolean]
61
+ # @see RDF::Value#variable?
62
+ def variable?
63
+ true
64
+ end
65
+
57
66
  ##
58
67
  # Returns `true` if this variable has a name.
59
68
  #
@@ -108,7 +108,15 @@ module RDF
108
108
  end
109
109
 
110
110
  ##
111
- # Outputs a developer-friendly representation of this repository to
111
+ # Returns a developer-friendly representation of this object.
112
+ #
113
+ # @return [String]
114
+ def inspect
115
+ sprintf("#<%s:%#0x(%s)>", self.class.name, object_id, uri.to_s)
116
+ end
117
+
118
+ ##
119
+ # Outputs a developer-friendly representation of this object to
112
120
  # `stderr`.
113
121
  #
114
122
  # @return [void]
data/lib/rdf/version.rb CHANGED
@@ -2,8 +2,8 @@ module RDF
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 6
6
- EXTRA = 1
5
+ TINY = 7
6
+ EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  STRING << ".#{EXTRA}" if EXTRA
metadata CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 6
9
- - 1
10
- version: 0.1.6.1
8
+ - 7
9
+ version: 0.1.7
11
10
  platform: ruby
12
11
  authors:
13
12
  - Arto Bendiken
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-04-12 00:00:00 +02:00
18
+ date: 2010-04-16 00:00:00 +02:00
20
19
  default_executable: rdf
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency