rdf 3.2.3 → 3.2.6

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: 4482866c0eb2c223af0f3a88f1eba8e1e2126c238c1136ff992a795de5047699
4
- data.tar.gz: 38e58d5e2bab26f76b55affe2cb362aff85afb49c7692056837b69d34cad6081
3
+ metadata.gz: 58dcc9836c4302cad4bb46a86596235794a664d508cc002ce298b6c964265ba9
4
+ data.tar.gz: 941a3daf3a379acf33fe09688ea9cabefd25eb88dc80a7b31d05ac380b2cb2f9
5
5
  SHA512:
6
- metadata.gz: 464c0043d3238fc3c4b077dfe6144a145b2c636b0e7de53ea6e8ce7ea96d2fd196b88053b1974d939650295416a2e4f07d298009d06d3a0320c297caf7883309
7
- data.tar.gz: 0b27d632fe51c621bd50c27c2b7ecf5da91cd615e4e39ddf82e9f65517bddadcba4adb387a33807f8f2f0851b3a1d3c0429ccf41f4ec1610371c57fe28bd0709
6
+ metadata.gz: f384a93b62b93d574c3dae02e8285f77a3ea6fa26c60eb30aa387e7213343e763a00d9a58f33d0caf4acc5f68a4b27e55361beb792127486059e8afeb333053e
7
+ data.tar.gz: ed8a19309a2b2f042a3f10df60465b56bd5ea9ace1a305cbe595bab507a7606eae99438fe3ce1edbcd653f513bd015aaf19d5e7203c5903278e275dc591e9d15
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  This is a pure-Ruby library for working with [Resource Description Framework
4
4
  (RDF)][RDF] data.
5
5
 
6
- * <https://ruby-rdf.github.com/rdf>
6
+ * <https://ruby-rdf.github.io/rdf>
7
7
 
8
8
  [![Gem Version](https://badge.fury.io/rb/rdf.png)](https://badge.fury.io/rb/rdf)
9
9
  [![Build Status](https://github.com/ruby-rdf/rdf/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/rdf/actions?query=workflow%3ACI)
@@ -141,11 +141,11 @@ or
141
141
  ### Reading RDF data in the [N-Triples][] format
142
142
 
143
143
  require 'rdf/ntriples'
144
- graph = RDF::Graph.load("https://ruby-rdf.github.com/rdf/etc/doap.nt")
144
+ graph = RDF::Graph.load("https://ruby-rdf.github.io/rdf/etc/doap.nt")
145
145
 
146
146
  or
147
147
 
148
- RDF::Reader.open("https://ruby-rdf.github.com/rdf/etc/doap.nt") do |reader|
148
+ RDF::Reader.open("https://ruby-rdf.github.io/rdf/etc/doap.nt") do |reader|
149
149
  reader.each_statement do |statement|
150
150
  puts statement.inspect
151
151
  end
@@ -160,13 +160,13 @@ MimeType or file extension, where available.
160
160
 
161
161
  require 'rdf/nquads'
162
162
 
163
- graph = RDF::Graph.load("https://ruby-rdf.github.com/rdf/etc/doap.nq", format: :nquads)
163
+ graph = RDF::Graph.load("https://ruby-rdf.github.io/rdf/etc/doap.nq", format: :nquads)
164
164
 
165
165
  A specific sub-type of Reader can also be invoked directly:
166
166
 
167
167
  require 'rdf/nquads'
168
168
 
169
- RDF::NQuads::Reader.open("https://ruby-rdf.github.com/rdf/etc/doap.nq") do |reader|
169
+ RDF::NQuads::Reader.open("https://ruby-rdf.github.io/rdf/etc/doap.nq") do |reader|
170
170
  reader.each_statement do |statement|
171
171
  puts statement.inspect
172
172
  end
@@ -220,7 +220,7 @@ Note that no prefixes are loaded automatically, however they can be provided as
220
220
 
221
221
  require 'rdf/ntriples'
222
222
 
223
- graph = RDF::Graph.load("https://ruby-rdf.github.com/rdf/etc/doap.nt")
223
+ graph = RDF::Graph.load("https://ruby-rdf.github.io/rdf/etc/doap.nt")
224
224
  query = RDF::Query.new({
225
225
  person: {
226
226
  RDF.type => FOAF.Person,
@@ -295,7 +295,7 @@ Readers support a boolean valued `rdfstar` option.
295
295
 
296
296
  ## Documentation
297
297
 
298
- <https://rubydoc.info/github/ruby-rdf/rdf>
298
+ <https://ruby-rdf.github.io/rdf>
299
299
 
300
300
  ### RDF Object Model
301
301
 
@@ -309,7 +309,7 @@ Readers support a boolean valued `rdfstar` option.
309
309
  * {RDF::Literal::Double}
310
310
  * {RDF::Literal::Integer}
311
311
  * {RDF::Literal::Time}
312
- * [RDF::XSD](https://rubydoc.info/github/gkellogg/rdf-xsd) (extension)
312
+ * [RDF::XSD](https://ruby-rdf.github.io/rdf-xsd) (extension)
313
313
  * {RDF::Resource}
314
314
  * {RDF::Node}
315
315
  * {RDF::URI}
@@ -371,10 +371,10 @@ from BNode identity (i.e., they each entail the other)
371
371
  * {RDF::Mutable}
372
372
  * {RDF::Durable}
373
373
  * {RDF::Transaction}
374
- * [RDF::AllegroGraph](https://rubydoc.info/github/ruby-rdf/rdf-agraph) (extension)
375
- * [RDF::Mongo](https://rubydoc.info/github/ruby-rdf/rdf-mongo) (extension)
376
- * [RDF::DataObjects](https://rubydoc.info/github/ruby-rdf/rdf-do) (extension)
377
- * [RDF::Sesame](https://rubydoc.info/github/ruby-rdf/rdf-sesame) (extension)
374
+ * [RDF::AllegroGraph](https://ruby-rdf.github.io/rdf-agraph) (extension)
375
+ * [RDF::Mongo](https://ruby-rdf.github.io/rdf-mongo) (extension)
376
+ * [RDF::DataObjects](https://ruby-rdf.github.io/rdf-do) (extension)
377
+ * [RDF::Sesame](https://ruby-rdf.github.io/rdf-sesame) (extension)
378
378
 
379
379
  ### RDF Querying
380
380
 
@@ -384,7 +384,7 @@ from BNode identity (i.e., they each entail the other)
384
384
  * {RDF::Query::Solution}
385
385
  * {RDF::Query::Solutions}
386
386
  * {RDF::Query::Variable}
387
- * [SPARQL](https://rubydoc.info/github/ruby-rdf/sparql) (extension)
387
+ * [SPARQL](https://ruby-rdf.github.io/sparql) (extension)
388
388
 
389
389
 
390
390
  ### RDF Vocabularies
@@ -422,7 +422,7 @@ follows:
422
422
 
423
423
  ## Resources
424
424
 
425
- * <https://rubydoc.info/github/ruby-rdf/rdf>
425
+ * <https://ruby-rdf.github.io/rdf>
426
426
  * <https://github.com/ruby-rdf/rdf>
427
427
  * <https://rubygems.org/gems/rdf>
428
428
  * <https://www.ohloh.net/p/rdf>
@@ -486,33 +486,33 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
486
486
  [YARD]: https://yardoc.org/
487
487
  [YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
488
488
  [PDD]: https://unlicense.org/#unlicensing-contributions
489
- [JSONLD doc]: https://rubydoc.info/github/ruby-rdf/json-ld
490
- [LinkedData doc]: https://rubydoc.info/github/ruby-rdf/linkeddata
491
- [Microdata doc]: https://rubydoc.info/github/ruby-rdf/rdf-microdata
492
- [N3 doc]: https://rubydoc.info/github/ruby-rdf/rdf-n3
493
- [RDFa doc]: https://rubydoc.info/github/ruby-rdf/rdf-rdfa
494
- [RDFXML doc]: https://rubydoc.info/github/ruby-rdf/rdf-rdfxml
495
- [Turtle doc]: https://rubydoc.info/github/ruby-rdf/rdf-turtle
496
- [SPARQL doc]: https://rubydoc.info/github/ruby-rdf/sparql
489
+ [JSONLD doc]: https://ruby-rdf.github.io/json-ld
490
+ [LinkedData doc]: https://ruby-rdf.github.io/linkeddata
491
+ [Microdata doc]: https://ruby-rdf.github.io/rdf-microdata
492
+ [N3 doc]: https://ruby-rdf.github.io/rdf-n3
493
+ [RDFa doc]: https://ruby-rdf.github.io/rdf-rdfa
494
+ [RDFXML doc]: https://ruby-rdf.github.io/rdf-rdfxml
495
+ [Turtle doc]: https://ruby-rdf.github.io/rdf-turtle
496
+ [SPARQL doc]: https://ruby-rdf.github.io/sparql
497
497
  [RDF 1.0]: https://www.w3.org/TR/2004/REC-rdf-concepts-20040210/
498
498
  [RDF 1.1]: https://www.w3.org/TR/rdf11-concepts/
499
499
  [SPARQL 1.1]: https://www.w3.org/TR/sparql11-query/
500
- [RDF.rb]: https://ruby-rdf.github.com/
501
- [RDF::DO]: https://ruby-rdf.github.com/rdf-do
502
- [RDF::Mongo]: https://ruby-rdf.github.com/rdf-mongo
503
- [RDF::Sesame]: https://ruby-rdf.github.com/rdf-sesame
504
- [RDF::JSON]: https://ruby-rdf.github.com/rdf-json
505
- [RDF::Microdata]: https://ruby-rdf.github.com/rdf-microdata
506
- [RDF::N3]: https://ruby-rdf.github.com/rdf-n3
507
- [RDF::RDFa]: https://ruby-rdf.github.com/rdf-rdfa
508
- [RDF::RDFXML]: https://ruby-rdf.github.com/rdf-rdfxml
509
- [RDF::TriG]: https://ruby-rdf.github.com/rdf-trig
510
- [RDF::TriX]: https://ruby-rdf.github.com/rdf-trix
511
- [RDF::Turtle]: https://ruby-rdf.github.com/rdf-turtle
512
- [RDF::Raptor]: https://ruby-rdf.github.com/rdf-raptor
500
+ [RDF.rb]: https://ruby-rdf.github.io/
501
+ [RDF::DO]: https://ruby-rdf.github.io/rdf-do
502
+ [RDF::Mongo]: https://ruby-rdf.github.io/rdf-mongo
503
+ [RDF::Sesame]: https://ruby-rdf.github.io/rdf-sesame
504
+ [RDF::JSON]: https://ruby-rdf.github.io/rdf-json
505
+ [RDF::Microdata]: https://ruby-rdf.github.io/rdf-microdata
506
+ [RDF::N3]: https://ruby-rdf.github.io/rdf-n3
507
+ [RDF::RDFa]: https://ruby-rdf.github.io/rdf-rdfa
508
+ [RDF::RDFXML]: https://ruby-rdf.github.io/rdf-rdfxml
509
+ [RDF::TriG]: https://ruby-rdf.github.io/rdf-trig
510
+ [RDF::TriX]: https://ruby-rdf.github.io/rdf-trix
511
+ [RDF::Turtle]: https://ruby-rdf.github.io/rdf-turtle
512
+ [RDF::Raptor]: https://ruby-rdf.github.io/rdf-raptor
513
513
  [RDF*]: https://w3c.github.io/rdf-star/rdf-star-cg-spec.html
514
- [LinkedData]: https://ruby-rdf.github.com/linkeddata
515
- [JSON::LD]: https://ruby-rdf.github.com/json-ld
514
+ [LinkedData]: https://ruby-rdf.github.io/linkeddata
515
+ [JSON::LD]: https://ruby-rdf.github.io/json-ld
516
516
  [RestClient]: https://rubygems.org/gems/rest-client
517
517
  [RestClient Components]: https://rubygems.org/gems/rest-client-components
518
518
  [Rack::Cache]: https://rtomayko.github.io/rack-cache/
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.3
1
+ 3.2.6
@@ -2,9 +2,13 @@ module RDF
2
2
  ##
3
3
  # @since 0.2.0
4
4
  module Countable
5
- autoload :Enumerator, 'rdf/mixin/enumerator'
6
5
  extend RDF::Util::Aliasing::LateBound
7
6
 
7
+ # Extends Enumerator with {Countable}, which is used by {Countable#enum_for}
8
+ class Enumerator < ::Enumerator
9
+ include RDF::Countable
10
+ end
11
+
8
12
  ##
9
13
  # Returns `true` if `self` contains no RDF statements.
10
14
  #
@@ -57,11 +57,23 @@ module RDF
57
57
  # @see RDF::Graph
58
58
  # @see RDF::Repository
59
59
  module Enumerable
60
- autoload :Enumerator, 'rdf/mixin/enumerator'
61
60
  extend RDF::Util::Aliasing::LateBound
62
61
  include ::Enumerable
63
62
  include RDF::Countable # NOTE: must come after ::Enumerable
64
63
 
64
+ # Extends Enumerator with {Queryable} and {Enumerable}, which is used by {Enumerable#each_statement} and {Queryable#enum_for}
65
+ class Enumerator < ::Enumerator
66
+ include RDF::Queryable
67
+ include RDF::Enumerable
68
+
69
+ ##
70
+ # @return [Array]
71
+ # @note Make sure returned arrays are also queryable
72
+ def to_a
73
+ return super.to_a.extend(RDF::Queryable, RDF::Enumerable)
74
+ end
75
+ end
76
+
65
77
  ##
66
78
  # Returns `true` if this enumerable supports the given `feature`.
67
79
  #
@@ -9,9 +9,21 @@ module RDF
9
9
  # @see RDF::Graph
10
10
  # @see RDF::Repository
11
11
  module Queryable
12
- autoload :Enumerator, 'rdf/mixin/enumerator'
13
12
  include ::Enumerable
14
13
 
14
+ # Extends Enumerator with {Queryable} and {Enumerable}, which is used by {Enumerable#each_statement} and {Queryable#enum_for}
15
+ class Enumerator < ::Enumerator
16
+ include RDF::Queryable
17
+ include RDF::Enumerable
18
+
19
+ ##
20
+ # @return [Array]
21
+ # @note Make sure returned arrays are also queryable
22
+ def to_a
23
+ return super.to_a.extend(RDF::Queryable, RDF::Enumerable)
24
+ end
25
+ end
26
+
15
27
  ##
16
28
  # Queries `self` for RDF statements matching the given `pattern`.
17
29
  #
@@ -476,7 +476,7 @@ module RDF
476
476
  # @return [Integer]
477
477
  # @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-3C-3D-3E
478
478
  def eql?(other)
479
- to_a.eql? other.to_a # TODO: optimize this
479
+ to_a.eql? Array(other)
480
480
  end
481
481
 
482
482
  ##
@@ -4,67 +4,41 @@ module RDF; class Literal
4
4
  #
5
5
  # @see http://www.w3.org/TR/xmlschema11-2/#date
6
6
  # @since 0.2.1
7
- class Date < Literal
7
+ class Date < Temporal
8
8
  DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#date")
9
9
  GRAMMAR = %r(\A(-?\d{4}-\d{2}-\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)?\Z).freeze
10
10
  FORMAT = '%Y-%m-%d'.freeze
11
11
 
12
12
  ##
13
- # @param [String, Date, #to_date] value
13
+ # Internally, a `Date` is represented using a native `::DateTime` object at midnight. If initialized from a `::Date`, there is no timezone component, If initialized from a `::DateTime`, the timezone is taken from that native object, otherwise, a timezone (or no timezone) is taken from the string representation having a matching `zzzzzz` component.
14
+ #
15
+ # @note If initialized using the `#to_datetime` method, time component is unchanged. Otherewise, it is set to 00:00 (midnight).
16
+ #
17
+ # @param [String, Date, #to_datetime] value
14
18
  # @param (see Literal#initialize)
15
19
  def initialize(value, datatype: nil, lexical: nil, **options)
16
20
  @datatype = RDF::URI(datatype || self.class.const_get(:DATATYPE))
17
21
  @string = lexical || (value if value.is_a?(String))
18
22
  @object = case
19
- when value.is_a?(::Date) then value
20
- when value.respond_to?(:to_date) then value.to_date
21
- else ::Date.parse(value.to_s)
22
- end rescue ::Date.new
23
- end
24
-
25
- ##
26
- # Converts this literal into its canonical lexical representation.
27
- #
28
- # Note that the timezone is recoverable for xsd:date, where it is not for xsd:dateTime and xsd:time, which are both transformed relative to Z, if a timezone is provided.
29
- #
30
- # @return [RDF::Literal] `self`
31
- # @see http://www.w3.org/TR/xmlschema11-2/#date
32
- def canonicalize!
33
- @string = @object.strftime(FORMAT) + self.tz.to_s if self.valid?
34
- self
35
- end
36
-
37
- ##
38
- # Returns `true` if the value adheres to the defined grammar of the
39
- # datatype.
40
- #
41
- # Special case for date and dateTime, for which '0000' is not a valid year
42
- #
43
- # @return [Boolean]
44
- # @since 0.2.1
45
- def valid?
46
- super && object && value !~ %r(\A0000)
47
- end
48
-
49
- ##
50
- # Does the literal representation include a timezone? Note that this is only possible if initialized using a string, or `:lexical` option.
51
- #
52
- # @return [Boolean]
53
- # @since 1.1.6
54
- def timezone?
55
- md = self.to_s.match(GRAMMAR)
56
- md && !!md[2]
57
- end
58
- alias_method :tz?, :timezone?
59
- alias_method :has_tz?, :timezone?
60
- alias_method :has_timezone?, :timezone?
61
-
62
- ##
63
- # Returns the value as a string.
64
- #
65
- # @return [String]
66
- def to_s
67
- @string || @object.strftime(FORMAT)
23
+ when value.class == ::Date
24
+ @zone = nil
25
+ # Use midnight as midpoint of the interval
26
+ ::DateTime.parse(value.strftime('%FT00:00:00'))
27
+ when value.respond_to?(:to_datetime)
28
+ dt = value.to_datetime
29
+ @zone = dt.zone
30
+ dt
31
+ else
32
+ md = value.to_s.match(GRAMMAR)
33
+ _, dt, tz = Array(md)
34
+ if tz
35
+ @zone = tz == 'Z' ? '+00:00' : tz
36
+ else
37
+ @zone = nil # No timezone
38
+ end
39
+ # Use midnight as midpoint of the interval
40
+ ::DateTime.parse("#{dt}T00:00:00#{@zone}")
41
+ end rescue ::DateTime.new
68
42
  end
69
43
 
70
44
  ##
@@ -75,42 +49,13 @@ module RDF; class Literal
75
49
  def humanize(lang = :en)
76
50
  d = object.strftime("%A, %d %B %Y")
77
51
  if timezone?
78
- d += if self.tz == 'Z'
52
+ d += if @zone == '+00:00'
79
53
  " UTC"
80
54
  else
81
- " #{self.tz}"
55
+ " #{@zone}"
82
56
  end
83
57
  end
84
58
  d
85
59
  end
86
-
87
- ##
88
- # Returns the timezone part of arg as a simple literal. Returns the empty string if there is no timezone.
89
- #
90
- # @return [RDF::Literal]
91
- # @since 1.1.6
92
- def tz
93
- md = self.to_s.match(GRAMMAR)
94
- zone = md[2].to_s
95
- zone = "Z" if zone == "+00:00"
96
- RDF::Literal(zone)
97
- end
98
-
99
- ##
100
- # Equal compares as Date objects
101
- def ==(other)
102
- # If lexically invalid, use regular literal testing
103
- return super unless self.valid?
104
-
105
- case other
106
- when Literal::Date
107
- return super unless other.valid?
108
- self.object == other.object
109
- when Literal::Time, Literal::DateTime
110
- false
111
- else
112
- super
113
- end
114
- end
115
60
  end # Date
116
61
  end; end # RDF::Literal
@@ -2,117 +2,38 @@ module RDF; class Literal
2
2
  ##
3
3
  # A date/time literal.
4
4
  #
5
- # @see http://www.w3.org/TR/xmlschema11-2/#dateTime#boolean
5
+ # @see http://www.w3.org/TR/xmlschema11-2/#dateTime
6
6
  # @since 0.2.1
7
- class DateTime < Literal
7
+ class DateTime < Temporal
8
8
  DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#dateTime")
9
9
  GRAMMAR = %r(\A(-?(?:\d{4}|[1-9]\d{4,})-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?)((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)?\Z).freeze
10
- FORMAT = '%Y-%m-%dT%H:%M:%S.%L%:z'.freeze
10
+ FORMAT = '%Y-%m-%dT%H:%M:%S.%L'.freeze
11
11
 
12
12
  ##
13
+ # Internally, a `DateTime` is represented using a native `::DateTime`. If initialized from a `::Date`, there is no timezone component, If initialized from a `::DateTime`, the timezone is taken from that native object, otherwise, a timezone (or no timezone) is taken from the string representation having a matching `zzzzzz` component.
14
+ #
13
15
  # @param [DateTime] value
14
16
  # @option options [String] :lexical (nil)
15
17
  def initialize(value, datatype: nil, lexical: nil, **options)
16
18
  @datatype = RDF::URI(datatype || self.class.const_get(:DATATYPE))
17
19
  @string = lexical || (value if value.is_a?(String))
18
20
  @object = case
19
- when value.is_a?(::DateTime) then value
20
- when value.respond_to?(:to_datetime) then value.to_datetime
21
- else ::DateTime.parse(value.to_s)
22
- end rescue ::DateTime.new
23
- end
24
-
25
- ##
26
- # Converts this literal into its canonical lexical representation.
27
- # with date and time normalized to UTC.
28
- #
29
- # @return [RDF::Literal] `self`
30
- # @see http://www.w3.org/TR/xmlschema11-2/#dateTime
31
- def canonicalize!
32
- if self.valid?
33
- @string = if timezone?
34
- @object.new_offset.new_offset.strftime(FORMAT[0..-4] + 'Z').sub('.000', '')
21
+ when value.is_a?(::DateTime)
22
+ @zone = value.zone
23
+ value
24
+ when value.respond_to?(:to_datetime)
25
+ @zone = value.to_datetime.zone
26
+ value.to_datetime
35
27
  else
36
- @object.strftime(FORMAT[0..-4]).sub('.000', '')
37
- end
38
- end
39
- self
40
- end
41
-
42
- ##
43
- # Returns the timezone part of arg as a simple literal. Returns the empty string if there is no timezone.
44
- #
45
- # @return [RDF::Literal]
46
- # @see http://www.w3.org/TR/sparql11-query/#func-tz
47
- def tz
48
- zone = timezone? ? object.zone : ""
49
- zone = "Z" if zone == "+00:00"
50
- RDF::Literal(zone)
51
- end
52
-
53
- ##
54
- # Returns the timezone part of arg as an xsd:dayTimeDuration, or `nil`
55
- # if lexical form of literal does not include a timezone.
56
- #
57
- # @return [RDF::Literal]
58
- def timezone
59
- if tz == 'Z'
60
- RDF::Literal("PT0S", datatype: RDF::URI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))
61
- elsif md = tz.to_s.match(/^([+-])?(\d+):(\d+)?$/)
62
- plus_minus, hour, min = md[1,3]
63
- plus_minus = nil unless plus_minus == "-"
64
- hour = hour.to_i
65
- min = min.to_i
66
- res = "#{plus_minus}PT#{hour}H#{"#{min}M" if min > 0}"
67
- RDF::Literal(res, datatype: RDF::URI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))
68
- end
69
- end
70
-
71
- ##
72
- # Returns `true` if the value adheres to the defined grammar of the
73
- # datatype.
74
- #
75
- # Special case for date and dateTime, for which '0000' is not a valid year
76
- #
77
- # @return [Boolean]
78
- # @since 0.2.1
79
- def valid?
80
- super && object && value !~ %r(\A0000)
81
- end
82
-
83
- ##
84
- # Does the literal representation include millisectonds?
85
- #
86
- # @return [Boolean]
87
- # @since 1.1.6
88
- def milliseconds?
89
- self.format("%L").to_i > 0
90
- end
91
- alias_method :has_milliseconds?, :milliseconds?
92
- alias_method :has_ms?, :milliseconds?
93
- alias_method :ms?, :milliseconds?
94
-
95
- ##
96
- # Does the literal representation include a timezone? Note that this is only possible if initialized using a string, or `:lexical` option.
97
- #
98
- # @return [Boolean]
99
- # @since 1.1.6
100
- def timezone?
101
- md = self.to_s.match(GRAMMAR)
102
- md && !!md[2]
103
- end
104
- alias_method :tz?, :timezone?
105
- alias_method :has_tz?, :timezone?
106
- alias_method :has_timezone?, :timezone?
107
-
108
- ##
109
- # Returns the `timezone` of the literal. If the
110
- ##
111
- # Returns the value as a string.
112
- #
113
- # @return [String]
114
- def to_s
115
- @string || @object.strftime(FORMAT).sub("+00:00", 'Z').sub('.000', '')
28
+ md = value.to_s.match(GRAMMAR)
29
+ _, _, tz = Array(md)
30
+ if tz
31
+ @zone = tz == 'Z' ? '+00:00' : tz
32
+ else
33
+ @zone = nil # No timezone
34
+ end
35
+ ::DateTime.parse(value.to_s)
36
+ end rescue ::DateTime.new
116
37
  end
117
38
 
118
39
  ##
@@ -123,31 +44,10 @@ module RDF; class Literal
123
44
  def humanize(lang = :en)
124
45
  d = object.strftime("%r on %A, %d %B %Y")
125
46
  if timezone?
126
- zone = if self.tz == 'Z'
127
- "UTC"
128
- else
129
- self.tz
130
- end
131
- d.sub!(" on ", " #{zone} on ")
47
+ z = @zone == '+00:00' ? "UTC" : @zone
48
+ d.sub!(" on ", " #{z} on ")
132
49
  end
133
50
  d
134
51
  end
135
-
136
- ##
137
- # Equal compares as DateTime objects
138
- def ==(other)
139
- # If lexically invalid, use regular literal testing
140
- return super unless self.valid?
141
-
142
- case other
143
- when Literal::DateTime
144
- return super unless other.valid?
145
- self.object == other.object
146
- when Literal::Time, Literal::Date
147
- false
148
- else
149
- super
150
- end
151
- end
152
52
  end # DateTime
153
53
  end; end # RDF::Literal
@@ -54,7 +54,10 @@ module RDF; class Literal
54
54
  ##
55
55
  # Returns the absolute value of `self`.
56
56
  #
57
+ # From the XQuery function [fn:abs](https://www.w3.org/TR/xpath-functions/#func-abs).
58
+ #
57
59
  # @return [RDF::Literal]
60
+ # @see https://www.w3.org/TR/xpath-functions/#func-abs
58
61
  # @since 0.2.3
59
62
  def abs
60
63
  (d = to_d) && d > 0 ? self : RDF::Literal(d.abs)
@@ -63,7 +66,10 @@ module RDF; class Literal
63
66
  ##
64
67
  # Returns the number with no fractional part that is closest to the argument. If there are two such numbers, then the one that is closest to positive infinity is returned. An error is raised if arg is not a numeric value.
65
68
  #
69
+ # From the XQuery function [fn:round](https://www.w3.org/TR/xpath-functions/#func-round).
70
+ #
66
71
  # @return [RDF::Literal::Decimal]
72
+ # @see https://www.w3.org/TR/xpath-functions/#func-round
67
73
  def round
68
74
  rounded = to_d.round(half: (to_d < 0 ? :down : :up))
69
75
  if rounded == -0.0
@@ -77,10 +83,13 @@ module RDF; class Literal
77
83
  ##
78
84
  # Returns the smallest integer greater than or equal to `self`.
79
85
  #
86
+ # From the XQuery function [fn:ceil](https://www.w3.org/TR/xpath-functions/#func-ceil).
87
+ #
80
88
  # @example
81
89
  # RDF::Literal(1).ceil #=> RDF::Literal(1)
82
90
  #
83
91
  # @return [RDF::Literal::Integer]
92
+ # @see https://www.w3.org/TR/xpath-functions/#func-ceil
84
93
  def ceil
85
94
  RDF::Literal::Integer.new(to_d.ceil)
86
95
  end
@@ -88,10 +97,13 @@ module RDF; class Literal
88
97
  ##
89
98
  # Returns the largest integer less than or equal to `self`.
90
99
  #
100
+ # From the XQuery function [fn:floor](https://www.w3.org/TR/xpath-functions/#func-floor).
101
+ #
91
102
  # @example
92
103
  # RDF::Literal(1).floor #=> RDF::Literal(1)
93
104
  #
94
105
  # @return [RDF::Literal::Integer]
106
+ # @see https://www.w3.org/TR/xpath-functions/#func-floor
95
107
  def floor
96
108
  RDF::Literal::Integer.new(to_d.floor)
97
109
  end
@@ -34,6 +34,14 @@ module RDF; class Literal
34
34
  end
35
35
  end
36
36
 
37
+ # Approximation of the mathematical constant π
38
+ #
39
+ # From the XQuery function [math:pi](https://www.w3.org/TR/xpath-functions/#func-math-pi).
40
+ #
41
+ # @return [Double]
42
+ # @see https://www.w3.org/TR/xpath-functions/#func-math-pi
43
+ PI = Double.new(Math::PI)
44
+
37
45
  ##
38
46
  # Converts this literal into its canonical lexical representation.
39
47
  #
@@ -145,6 +153,8 @@ module RDF; class Literal
145
153
  ##
146
154
  # Returns the smallest integer greater than or equal to `self`.
147
155
  #
156
+ # From the XQuery function [fn:ceil](https://www.w3.org/TR/xpath-functions/#func-ceil).
157
+ #
148
158
  # @example
149
159
  # RDF::Literal(1.2).ceil #=> RDF::Literal(2)
150
160
  # RDF::Literal(-1.2).ceil #=> RDF::Literal(-1)
@@ -152,6 +162,7 @@ module RDF; class Literal
152
162
  # RDF::Literal(-2.0).ceil #=> RDF::Literal(-2)
153
163
  #
154
164
  # @return [RDF::Literal::Integer]
165
+ # @see https://www.w3.org/TR/xpath-functions/#func-ceil
155
166
  # @since 0.2.3
156
167
  def ceil
157
168
  RDF::Literal::Integer.new(to_f.ceil)
@@ -160,6 +171,8 @@ module RDF; class Literal
160
171
  ##
161
172
  # Returns the largest integer less than or equal to `self`.
162
173
  #
174
+ # From the XQuery function [fn:floor](https://www.w3.org/TR/xpath-functions/#func-floor).
175
+ #
163
176
  # @example
164
177
  # RDF::Literal(1.2).floor #=> RDF::Literal(1)
165
178
  # RDF::Literal(-1.2).floor #=> RDF::Literal(-2)
@@ -167,6 +180,7 @@ module RDF; class Literal
167
180
  # RDF::Literal(-2.0).floor #=> RDF::Literal(-2)
168
181
  #
169
182
  # @return [RDF::Literal::Integer]
183
+ # @see https://www.w3.org/TR/xpath-functions/#func-floor
170
184
  # @since 0.2.3
171
185
  def floor
172
186
  RDF::Literal::Integer.new(to_f.floor)
@@ -175,7 +189,10 @@ module RDF; class Literal
175
189
  ##
176
190
  # Returns the absolute value of `self`.
177
191
  #
192
+ # From the XQuery function [fn:abs](https://www.w3.org/TR/xpath-functions/#func-abs).
193
+ #
178
194
  # @return [RDF::Literal]
195
+ # @see https://www.w3.org/TR/xpath-functions/#func-abs
179
196
  # @since 0.2.3
180
197
  def abs
181
198
  (f = to_f) && f > 0 ? self : self.class.new(f.abs)
@@ -184,7 +201,10 @@ module RDF; class Literal
184
201
  ##
185
202
  # Returns the number with no fractional part that is closest to the argument. If there are two such numbers, then the one that is closest to positive infinity is returned. An error is raised if arg is not a numeric value.
186
203
  #
204
+ # From the XQuery function [fn:round](https://www.w3.org/TR/xpath-functions/#func-round).
205
+ #
187
206
  # @return [RDF::Literal::Double]
207
+ # @see https://www.w3.org/TR/xpath-functions/#func-round
188
208
  def round
189
209
  self.class.new(to_d.round(half: (to_d < 0 ? :down : :up)))
190
210
  end