rdf-xsd 1.1.2 → 1.1.3

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: 88c3fc78f625a07c1e4f7bd3e572039be95d39c7
4
- data.tar.gz: a4e9108ea175b57e2841ff37d55fa584682f7f3f
3
+ metadata.gz: 8c014eaaff792361c1d6fa05e26933472485d7aa
4
+ data.tar.gz: f63f51ec09699752ad13ad04af7e92faa072acb2
5
5
  SHA512:
6
- metadata.gz: ecfab1a047ad7509866c18a60fb5d56e8fe72544bab73853a517607fefeb79ede30906e446513950e1c9835e44b8f023475e28d0484deb039fce92546527a7a4
7
- data.tar.gz: 8586b94faec499fca481fa96a494e6053ce38ba612ac19e3b926e5c0efbc6186953c1e88b5129792b20a3355a31c4847b92a7fa401de81bdea409dc478628bb9
6
+ metadata.gz: 73c34000bb89d17d584115d821a8d33b3d8bae4c3e01a4db59d259b16d8f10fa88c21c8dbb0259af01b43fe351af334c932d85a5f54eabdd1b8dde945819a9d1
7
+ data.tar.gz: ec76f7f67c5d8b68a8552da55745f1c9446e7a6c6e42cd49eeea4309085c10a27b59e35b296bfd974f1820542814c97a185d79c3fd770aae88eef78e6e8ee052
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.1.3
@@ -14,7 +14,7 @@ module RDF; class Literal
14
14
  # This type should be used to specify the intention that the value fulfills
15
15
  # the role of a URI as defined by [RFC 2396], as amended by [RFC 2732].
16
16
  #
17
- # @see http://www.w3.org/TR/xmlschema-2/#anyURI
17
+ # @see http://www.w3.org/TR/xmlschema11-2/#anyURI
18
18
  # @see http://www.ietf.org/rfc/rfc2396.txt
19
19
  # @see http://www.ietf.org/rfc/rfc2732.txt
20
20
  class AnyURI < RDF::Literal
@@ -50,7 +50,7 @@ module RDF; class Literal
50
50
  # Converts this literal into its canonical lexical representation.
51
51
  #
52
52
  # @return [RDF::Literal] `self`
53
- # @see http://www.w3.org/TR/xmlschema-2/#dateTime
53
+ # @see http://www.w3.org/TR/xmlschema11-2/#dateTime
54
54
  def canonicalize!
55
55
  @string = ::Base64.encode64(@object)
56
56
  self
data/lib/rdf/xsd/date.rb CHANGED
@@ -2,6 +2,18 @@
2
2
  require 'rdf'
3
3
 
4
4
  module RDF; class Literal
5
+ ##
6
+ # dateTimeStamp
7
+ #
8
+ # The dateTimeStamp datatype is ·derived· from dateTime by giving the value required to its explicitTimezone facet. The result is that all values of dateTimeStamp are required to have explicit time zone offsets and the datatype is totally ordered.
9
+ #
10
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dateTimeStamp
11
+ class DateTimeStamp < RDF::Literal::DateTime
12
+ DATATYPE = XSD.dateTimeStamp
13
+ GRAMMAR = %r(\A(-?\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?)((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)\Z).freeze
14
+ FORMAT = '%Y-%m-%dT%H:%M:%SZ'.freeze
15
+ end
16
+
5
17
  ##
6
18
  # gYearMonth represents a specific gregorian month in a specific gregorian year. The value space of gYearMonth is
7
19
  # the set of Gregorian calendar months as defined in § 5.2.1 of [ISO 8601]. Specifically, it is a set of one-month
@@ -47,7 +59,7 @@ module RDF; class Literal
47
59
  # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#gMonthDay
48
60
  class MonthDay < RDF::Literal::Date
49
61
  DATATYPE = XSD.gMonthDay
50
- GRAMMAR = %r(\A(\d{2}-\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
62
+ GRAMMAR = %r(\A--(\d{2}-\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
51
63
  FORMAT = '%m-%d%Z'.freeze
52
64
 
53
65
  def initialize(value, options = {})
@@ -65,7 +77,7 @@ module RDF; class Literal
65
77
  # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#gDay
66
78
  class Day < RDF::Literal::Date
67
79
  DATATYPE = XSD.gDay
68
- GRAMMAR = %r(\A(\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
80
+ GRAMMAR = %r(\A---(\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
69
81
  FORMAT = '%d%Z'.freeze
70
82
 
71
83
  def initialize(value, options = {})
@@ -82,7 +94,7 @@ module RDF; class Literal
82
94
  # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#gMonth
83
95
  class Month < RDF::Literal::Date
84
96
  DATATYPE = XSD.gMonth
85
- GRAMMAR = %r(\A(\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
97
+ GRAMMAR = %r(\A--(\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
86
98
  FORMAT = '%m%Z'.freeze
87
99
 
88
100
  def initialize(value, options = {})
@@ -5,11 +5,27 @@ module RDF; class Literal
5
5
  ##
6
6
  # A duration literal.
7
7
  #
8
- # @see http://www.w3.org/TR/xmlschema-2/#duration
9
- # @since 0.2.1
8
+ # @see http://www.w3.org/TR/xmlschema11-2/#duration
10
9
  class Duration < Literal
11
10
  DATATYPE = XSD.duration
12
- GRAMMAR = %r(\A(-?)P(\d+Y)?(\d+M)?(\d+D)?T?(\d+H)?(\d+M)?([\d\.]+S)?\Z).freeze
11
+ GRAMMAR = %r(\A
12
+ (?<si>-)?
13
+ P(?:(?:(?:(?:(?<yr>\d+)Y)(?:(?<mo>\d+)M)?(?:(?<da>\d+)D)?)
14
+ | (?:(?:(?<mo>\d+)M)(?:(?<da>\d+)D)?)
15
+ | (?:(?<da>\d+)D)
16
+ )
17
+ (?:T(?:(?:(?:(?<hr>\d+)H)(?:(?<mi>\d+)M)?(?<se>\d+(?:\.\d+)?S)?)
18
+ | (?:(?:(?<mi>\d+)M)(?:(?<se>\d+(?:\.\d+)?)S)?)
19
+ | (?:(?<se>\d+(?:\.\d+)?)S)
20
+ )
21
+ )?
22
+ |(?:T(?:(?:(?:(?<hr>\d+)H)(?:(?<mi>\d+)M)?(?<se>\d+(?:\.\d+)?S)?)
23
+ | (?:(?:(?<mi>\d+)M)(?:(?<se>\d+(?:\.\d+)?)S)?)
24
+ | (?:(?<se>\d+(?:\.\d+)?)S)
25
+ )
26
+ )
27
+ )
28
+ \z)x.freeze
13
29
 
14
30
  ##
15
31
  # * Given a Numeric, assumes that it is milliseconds
@@ -33,9 +49,8 @@ module RDF; class Literal
33
49
  when Duration, Numeric
34
50
  {:se => value.to_f}
35
51
  else
36
- parse(value.to_s) rescue { }
52
+ parse(value.to_s)
37
53
  end
38
- @object[:si] ||= 1
39
54
  end
40
55
 
41
56
  ##
@@ -44,11 +59,11 @@ module RDF; class Literal
44
59
  # Also normalizes elements
45
60
  #
46
61
  # @return [RDF::Literal] `self`
47
- # @see http://www.w3.org/TR/xmlschema-2/#dateTime
62
+ # @see http://www.w3.org/TR/xmlschema11-2/#dateTime
48
63
  def canonicalize!
49
64
  @string = @humanize = nil
50
65
  if @object[:se].to_i > 60
51
- m_r = (@object[:se].to_i / 60) - 1
66
+ m_r = (@object[:se].to_f / 60) - 1
52
67
  @object[:se] -= m_r * 60
53
68
  @object[:mi] = @object[:mi].to_i + m_r
54
69
  end
@@ -72,7 +87,7 @@ module RDF; class Literal
72
87
  @object[:mo] -= y_r * 12
73
88
  @object[:yr] = @object[:yr].to_i + y_r
74
89
  end
75
- @object.to_s # site-effect
90
+ @object.to_s # side-effect
76
91
  self
77
92
  end
78
93
 
@@ -83,7 +98,6 @@ module RDF; class Literal
83
98
  # Special case for date and dateTime, for which '0000' is not a valid year
84
99
  #
85
100
  # @return [Boolean]
86
- # @since 0.2.1
87
101
  def valid?
88
102
  !!(value =~ GRAMMAR)
89
103
  end
@@ -94,7 +108,7 @@ module RDF; class Literal
94
108
  # @return [String]
95
109
  def to_s
96
110
  @string ||= begin
97
- str = @object[:si] < 0 ? "-P" : "P"
111
+ str = @object[:si] == '-' ? "-P" : "P"
98
112
  str << "%dY" % @object[:yr].to_i if @object[:yr]
99
113
  str << "%dM" % @object[:mo].to_i if @object[:mo]
100
114
  str << "%dD" % @object[:da].to_i if @object[:da]
@@ -106,7 +120,7 @@ module RDF; class Literal
106
120
  end
107
121
 
108
122
  def plural(v, str)
109
- "#{v} #{str}#{v == 1 ? '' : 's'}" if v
123
+ "#{v} #{str}#{v.to_i == 1 ? '' : 's'}" if v
110
124
  end
111
125
 
112
126
  ##
@@ -126,7 +140,7 @@ module RDF; class Literal
126
140
  last = ar.pop
127
141
  first = ar.join(" ")
128
142
  res = first.empty? ? last : "#{first} and #{last}"
129
- @object[:si] < 0 ? "#{res} ago" : res
143
+ @object[:si] == '-' ? "#{res} ago" : res
130
144
  end
131
145
  end
132
146
 
@@ -159,7 +173,7 @@ module RDF; class Literal
159
173
  @object[:hr].to_i * 3600 +
160
174
  @object[:mi].to_i * 60 +
161
175
  @object[:se].to_f
162
- ) * @object[:si]
176
+ ) * (@object[:si] == '-' ? -1 : 1)
163
177
  end
164
178
 
165
179
  # @return [Integer]
@@ -174,22 +188,55 @@ module RDF; class Literal
174
188
  # @param [String] value XSD formatted duration
175
189
  # @return [Duration]
176
190
  def parse(value)
177
- hash = {}
178
- if value.to_s.match(GRAMMAR)
179
- hash[:si] = $1 == "-" ? -1 : 1
180
- hash[:yr] = $2.to_i if $2
181
- hash[:mo] = $3.to_i if $3
182
- hash[:da] = $4.to_i if $4
183
- hash[:hr] = $5.to_i if $5
184
- hash[:mi] = $6.to_i if $6
185
- hash[:se] = $7.to_f if $7
186
- end
187
- hash
191
+ value.to_s.match(GRAMMAR)
188
192
  end
189
193
 
190
194
  def sec_str
191
- usec = (@object[:se] * 1000).to_i % 1000
192
- usec > 0 ? ("%2.3f" % @object[:se]).sub(/0*\Z/, '') : @object[:se].to_i.to_s
195
+ sec = @object[:se].to_f
196
+ ((sec.truncate == sec ? "%d" : "%2.3f") % sec).sub(/(\.[1-9]+)0+$/, '\1')
193
197
  end
194
198
  end # Duration
199
+
200
+ ##
201
+ # A DayTimeDuration literal.
202
+ #
203
+ # dayTimeDuration is a datatype ·derived· from duration by restricting its ·lexical representations· to instances of dayTimeDurationLexicalRep. The ·value space· of dayTimeDuration is therefore that of duration restricted to those whose ·months· property is 0. This results in a duration datatype which is totally ordered.
204
+ #
205
+ # @see http://www.w3.org/TR/xmlschema11-2/#dayTimeDuration
206
+ class DayTimeDuration < Literal
207
+ DATATYPE = XSD.dayTimeDuration
208
+ GRAMMAR = %r(\A
209
+ (?<si>-)?
210
+ P(?:(?:(?:(?<da>\d+)D)
211
+ )
212
+ (?:T(?:(?:(?:(?<hr>\d+)H)(?:(?<mi>\d+)M)?(?<se>\d+(?:\.\d+)?S)?)
213
+ | (?:(?:(?<mi>\d+)M)(?:(?<se>\d+(?:\.\d+)?)S)?)
214
+ | (?:(?<se>\d+(?:\.\d+)?)S)
215
+ )
216
+ )?
217
+ |(?:T(?:(?:(?:(?<hr>\d+)H)(?:(?<mi>\d+)M)?(?<se>\d+(?:\.\d+)?S)?)
218
+ | (?:(?:(?<mi>\d+)M)(?:(?<se>\d+(?:\.\d+)?)S)?)
219
+ | (?:(?<se>\d+(?:\.\d+)?)S)
220
+ )
221
+ )
222
+ )
223
+ \z)x.freeze
224
+ end # DayTimeDuration
225
+
226
+ ##
227
+ # A YearMonthDuration literal.
228
+ #
229
+ # yearMonthDuration is a datatype ·derived· from duration by restricting its ·lexical representations· to instances of yearMonthDurationLexicalRep. The ·value space· of yearMonthDuration is therefore that of duration restricted to those whose ·seconds· property is 0. This results in a duration datatype which is totally ordered.
230
+ #
231
+ # @see http://www.w3.org/TR/xmlschema11-2/#yearMonthDuration
232
+ class YearMonthDuration < Literal
233
+ DATATYPE = XSD.yearMonthDuration
234
+ GRAMMAR = %r(\A
235
+ (?<si>-)?
236
+ P(?:(?:(?:(?:(?<yr>\d+)Y)(?:(?<mo>\d+)M)?)
237
+ | (?:(?:(?<mo>\d+)M))
238
+ )
239
+ )
240
+ \z)x.freeze
241
+ end # DayTimeDuration
195
242
  end; end # RDF::Literal
@@ -14,7 +14,6 @@ module RDF; class Literal
14
14
  # Returns `self` negated.
15
15
  #
16
16
  # @return [RDF::Literal::Numeric]
17
- # @since 0.2.3
18
17
  def -@
19
18
  if object != 0
20
19
  # XXX Raise error?
@@ -41,7 +40,6 @@ module RDF; class Literal
41
40
  # Returns `self` negated.
42
41
  #
43
42
  # @return [RDF::Literal::Numeric]
44
- # @since 0.2.3
45
43
  def -@
46
44
  if object != 0
47
45
  # XXX Raise error?
data/lib/rdf/xsd/xml.rb CHANGED
@@ -27,7 +27,6 @@ module RDF; class Literal
27
27
  # @see http://www.w3.org/TR/rdf-concepts/#section-XMLLiteral
28
28
  # @see http://www.w3.org/TR/rdfa-core/#s_xml_literals
29
29
  # @see http://www.w3.org/TR/xml-exc-c14n/
30
- # @since 0.2.1
31
30
  class XML < Literal
32
31
  DATATYPE = RDF.XMLLiteral
33
32
  GRAMMAR = nil
@@ -145,7 +144,6 @@ module RDF; class Literal
145
144
  # [DOM DocumentFragment](http://www.w3.org/TR/dom/#interface-documentfragment).
146
145
  #
147
146
  # @see https://dvcs.w3.org/hg/rdf/raw-file/default/rdf-concepts/index.html#section-html
148
- # @since 0.3.7
149
147
  class HTML < XML
150
148
  end
151
149
  end; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-xsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-13 00:00:00.000000000 Z
12
+ date: 2015-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -18,6 +18,9 @@ dependencies:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.1'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.9
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -25,6 +28,9 @@ dependencies:
25
28
  - - "~>"
26
29
  - !ruby/object:Gem::Version
27
30
  version: '1.1'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.9
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: activesupport
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
157
  version: '0'
152
158
  requirements: []
153
159
  rubyforge_project: rdf-xsd
154
- rubygems_version: 2.2.2
160
+ rubygems_version: 2.4.5
155
161
  signing_key:
156
162
  specification_version: 4
157
163
  summary: Extended XSD Datatypes for RDF.rb.