rdf-xsd 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ * Gregg Kellogg <gregg@kellogg-assoc.com>
data/README.markdown ADDED
@@ -0,0 +1,91 @@
1
+ # Extended XSD Datatypes for RDF.rb
2
+
3
+ This gem adds additional RDF::Literal subclasses for extended [XSD datatypes][]
4
+
5
+ * <http://github.com/gkellogg/rdf-xsd>
6
+
7
+ ## Features
8
+
9
+ * Additional xsd:integer subtypes
10
+ * xsd:float based on xsd:double
11
+ * xsd:duration
12
+
13
+ Examples
14
+ --------
15
+
16
+ require 'rdf'
17
+ require 'rdf/xsd'
18
+
19
+ ## Dependencies
20
+ * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.3.1)
21
+ * [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.3.3)
22
+ * [Haml](https://rubygems.org/gems/haml) (>= 3.0.0)
23
+
24
+ ## Documentation
25
+ Full documentation available on [Rubydoc.info][XSD doc]
26
+
27
+ ### Principle Classes
28
+ * {RDF::Literal::Float}
29
+ * {RDF::Literal::NonPositiveInteger}
30
+ * {RDF::Literal::NegativeInteger}
31
+ * {RDF::Literal::Long}
32
+ * {RDF::Literal::Int}
33
+ * {RDF::Literal::Short}
34
+ * {RDF::Literal::Byte}
35
+ * {RDF::Literal::NonNegativeInteger}
36
+ * {RDF::Literal::PositiveInteger}
37
+ * {RDF::Literal::UnsignedLong}
38
+ * {RDF::Literal::UnsignedInt}
39
+ * {RDF::Literal::UnsignedShort}
40
+ * {RDF::Literal::UnsignedByte}
41
+
42
+ ## Dependencies
43
+
44
+ * [Ruby](http://ruby-lang.org/) (>= 1.8.7) or (>= 1.8.1 with [Backports][])
45
+ * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.3.4)
46
+
47
+ ## Installation
48
+
49
+ The recommended installation method is via [RubyGems](http://rubygems.org/).
50
+ To install the latest official release of the `RDF::XSD` gem, do:
51
+
52
+ % [sudo] gem install rdf-xsd
53
+
54
+ ## Mailing List
55
+
56
+ * <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
57
+
58
+ ## Author
59
+
60
+ * [Gregg Kellogg](http://github.com/gkellogg) - <http://kellogg-assoc.com/>
61
+
62
+ Contributing
63
+ ------------
64
+
65
+ * Do your best to adhere to the existing coding conventions and idioms.
66
+ * Don't use hard tabs, and don't leave trailing whitespace on any line.
67
+ * Do document every method you add using [YARD][] annotations. Read the
68
+ [tutorial][YARD-GS] or just look at the existing code for examples.
69
+ * Don't touch the `.gemspec`, `VERSION` or `AUTHORS` files. If you need to
70
+ change them, do so on your private branch only.
71
+ * Do feel free to add yourself to the `CREDITS` file and the corresponding
72
+ list in the the `README`. Alphabetical order applies.
73
+ * Do note that in order for us to merge any non-trivial changes (as a rule
74
+ of thumb, additions larger than about 15 lines of code), we need an
75
+ explicit [public domain dedication][PDD] on record from you.
76
+
77
+ License
78
+ -------
79
+
80
+ This is free and unencumbered public domain software. For more information,
81
+ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
82
+
83
+ Portions of tests are derived from [W3C DAWG tests](http://www.w3.org/2001/sw/DataAccess/tests/) and have [other licensing terms](http://www.w3.org/2001/sw/DataAccess/tests/data-r2/LICENSE).
84
+
85
+ [Ruby]: http://ruby-lang.org/
86
+ [RDF]: http://www.w3.org/RDF/
87
+ [YARD]: http://yardoc.org/
88
+ [YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
89
+ [PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
90
+ [Backports]: http://rubygems.org/gems/backports
91
+ [XSD Datatypes]: http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#built-in-datatypes
data/UNLICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.3
data/lib/rdf/xsd.rb ADDED
@@ -0,0 +1,18 @@
1
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..')))
2
+ require 'rdf'
3
+
4
+ ##
5
+ # Plugin for RDF.rb for extended XSD datatypes.
6
+ #
7
+ # @example Requiring the `RDF::XSD` module
8
+ # require 'rdf/xsd'
9
+ #
10
+ # @see http://rdf.rubyforge.org/
11
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#built-in-datatypes
12
+ #
13
+ # @author [Gregg Kellogg](http://greggkellogg.net/)
14
+ module RDFa
15
+ autoload :VERSION, 'rdf/xsd/version'
16
+ end
17
+
18
+ Dir.glob(File.join(File.expand_path(File.dirname(__FILE__)), 'xsd', '*.rb')) {|f| require f}
@@ -0,0 +1,71 @@
1
+ require 'base64'
2
+
3
+ module RDF; class Literal
4
+ ##
5
+ # More specific sub-types of double
6
+ # Derived types
7
+ # @see http://www.w3.org/TR/xpath-functions/#datatypes
8
+
9
+ ##
10
+ # hexBinary represents arbitrary hex-encoded binary data. The value space of hexBinary is the set of finite-length
11
+ # sequences of binary octets.
12
+ #
13
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#hexBinary
14
+ class HexBinary < RDF::Literal
15
+ DATATYPE = XSD.hexBinary
16
+ GRAMMAR = %r(\A[0-9a-fA-F]+\Z)
17
+
18
+ ##
19
+ # Converts this literal into its canonical lexical representation.
20
+ #
21
+ # @return [RDF::Literal] `self`
22
+ def canonicalize!
23
+ @string = @object.downcase
24
+ self
25
+ end
26
+ end
27
+
28
+ ##
29
+ # base64Binary represents Base64-encoded arbitrary binary data. The ·value space· of base64Binary is the set of
30
+ # finite-length sequences of binary octets. For base64Binary data the entire binary stream is encoded using the Base64
31
+ # Alphabet in [RFC 2045].
32
+ #
33
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#hexBinary
34
+ class Base64Binary < RDF::Literal
35
+ DATATYPE = XSD.base64Binary
36
+
37
+ ##
38
+ # @param [String, Object] value
39
+ # If given a string, it will decode it as an object value.
40
+ # Otherwise, it will take the value as the object and encode to retrieve a value
41
+ # @option options [String] :lexical (nil)
42
+ def initialize(value, options = {})
43
+ super
44
+ @object = value.is_a?(String) ? ::Base64.decode64(value) : value
45
+ canonicalize! unless value.is_a?(String)
46
+ end
47
+
48
+ ##
49
+ # Converts this literal into its canonical lexical representation.
50
+ #
51
+ # @return [RDF::Literal] `self`
52
+ # @see http://www.w3.org/TR/xmlschema-2/#dateTime
53
+ def canonicalize!
54
+ @string = ::Base64.encode64(@object)
55
+ self
56
+ end
57
+
58
+ ##
59
+ # Returns `true` if the value adheres to the defined grammar of the
60
+ # datatype.
61
+ #
62
+ # @return [Boolean]
63
+ def valid?
64
+ Base64.strict_decode64(value.gsub(/\s+/m, ''))
65
+ true
66
+ rescue ArgumentError
67
+ STDERR.puts($!.inspect + ": #{value.inspect}")
68
+ false
69
+ end
70
+ end
71
+ end; end #RDF::Literal
@@ -0,0 +1,63 @@
1
+ require 'rdf'
2
+
3
+ module RDF; class Literal
4
+ ##
5
+ # gYearMonth represents a specific gregorian month in a specific gregorian year. The value space of gYearMonth is
6
+ # the set of Gregorian calendar months as defined in § 5.2.1 of [ISO 8601]. Specifically, it is a set of one-month
7
+ # long, non-periodic instances e.g. 1999-10 to represent the whole month of 1999-10, independent of how many days this
8
+ # month has.
9
+ #
10
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#gYearMonth
11
+ class YearMonth < RDF::Literal::Date
12
+ DATATYPE = XSD.gYearMonth
13
+ GRAMMAR = %r(\A-?\d{4,}-\d{2}((?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
14
+ FORMAT = '%Y-%m%Z'.freeze
15
+ end
16
+
17
+ ##
18
+ # gYear represents a gregorian calendar year. The value space of gYear is the set of Gregorian calendar years as
19
+ # defined in § 5.2.1 of [ISO 8601]. Specifically, it is a set of one-year long, non-periodic instances e.g. lexical
20
+ # 1999 to represent the whole year 1999, independent of how many months and days this year has.
21
+ #
22
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#gYear
23
+ class Year < RDF::Literal::Date
24
+ DATATYPE = XSD.gYear
25
+ GRAMMAR = %r(\A-?\d{4,}(?:(?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
26
+ FORMAT = '%Y%Z'.freeze
27
+ end
28
+
29
+ ##
30
+ # gMonthDay is a gregorian date that recurs, specifically a day of the year such as the third of May. Arbitrary
31
+ # recurring dates are not supported by this datatype. The value space of gMonthDay is the set of calendar dates,
32
+ # as defined in § 3 of [ISO 8601]. Specifically, it is a set of one-day long, annually periodic instances.
33
+ #
34
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#gMonthDay
35
+ class MonthDay < RDF::Literal::Date
36
+ DATATYPE = XSD.gMonthDay
37
+ GRAMMAR = %r(\A\d{2}-\d{2}(?:(?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
38
+ FORMAT = '%m-%d%Z'.freeze
39
+ end
40
+
41
+ ##
42
+ # gDay is a gregorian day that recurs, specifically a day of the month such as the 5th of the month. Arbitrary
43
+ # recurring days are not supported by this datatype. The value space of gDay is the space of a set of calendar
44
+ # dates as defined in § 3 of [ISO 8601]. Specifically, it is a set of one-day long, monthly periodic instances.
45
+ #
46
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#gDay
47
+ class Day < RDF::Literal::Date
48
+ DATATYPE = XSD.gDay
49
+ GRAMMAR = %r(\A\d{2}(?:(?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
50
+ FORMAT = '%d%Z'.freeze
51
+ end
52
+
53
+ ##
54
+ # gMonth is a gregorian month that recurs every year. The value space of gMonth is the space of a set of calendar
55
+ # months as defined in § 3 of [ISO 8601]. Specifically, it is a set of one-month long, yearly periodic instances.
56
+ #
57
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#gMonth
58
+ class Month < RDF::Literal::Date
59
+ DATATYPE = XSD.gMonth
60
+ GRAMMAR = %r(\A\d{2}(?:(?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
61
+ FORMAT = '%m%Z'.freeze
62
+ end
63
+ end; end #RDF::Literal
@@ -0,0 +1,8 @@
1
+ module RDF; class Literal
2
+ # Note that in XML Schema, Float is not really derived from Double,
3
+ # but implementations are identical in Ruby
4
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#float
5
+ class Float < Double
6
+ DATATYPE = XSD.float
7
+ end
8
+ end; end #RDF::Literal
@@ -0,0 +1,195 @@
1
+ require 'time'
2
+ require 'date'
3
+
4
+ module RDF; class Literal
5
+ ##
6
+ # A duration literal.
7
+ #
8
+ # @see http://www.w3.org/TR/xmlschema-2/#duration
9
+ # @since 0.2.1
10
+ class Duration < Literal
11
+ DATATYPE = XSD.duration
12
+ GRAMMAR = %r(\A(-?)P(\d+Y)?(\d+M)?(\d+D)?T?(\d+H)?(\d+M)?([\d\.]+S)?\Z).freeze
13
+
14
+ ##
15
+ # * Given a Numeric, assumes that it is milliseconds
16
+ # * Given a String, parse as xsd:duration
17
+ # * Hash form is used for internal representation
18
+ # @param [Duration, Hash, Numeric, #to_s] value
19
+ # @option options [String] :lexical (nil)
20
+ def initialize(value, options = {})
21
+ super
22
+ @object = case value
23
+ when Hash
24
+ value = value.dup
25
+ value[:yr] ||= value[:years]
26
+ value[:mo] ||= value[:months]
27
+ value[:da] ||= value[:days]
28
+ value[:hr] ||= value[:hours]
29
+ value[:mi] ||= value[:minutes]
30
+ value[:se] ||= value[:seconds]
31
+
32
+ value
33
+ when Duration, Numeric
34
+ {:se => value.to_f}
35
+ else
36
+ parse(value.to_s) rescue { }
37
+ end
38
+ @object[:si] ||= 1
39
+ end
40
+
41
+ ##
42
+ # Converts this literal into its canonical lexical representation.
43
+ #
44
+ # Also normalizes elements
45
+ #
46
+ # @return [RDF::Literal] `self`
47
+ # @see http://www.w3.org/TR/xmlschema-2/#dateTime
48
+ def canonicalize!
49
+ @string = @humanize = nil
50
+ if @object[:se].to_i > 60
51
+ m_r = (@object[:se].to_i / 60) - 1
52
+ @object[:se] -= m_r * 60
53
+ @object[:mi] = @object[:mi].to_i + m_r
54
+ end
55
+ if @object[:mi].to_i > 60
56
+ h_r = (@object[:mi].to_i / 60) - 1
57
+ @object[:mi] -= h_r * 60
58
+ @object[:hr] = @object[:hr].to_i + h_r
59
+ end
60
+ if @object[:hr].to_i > 24
61
+ d_r = (@object[:hr].to_i / 24) - 1
62
+ @object[:hr] -= d_r * 24
63
+ @object[:da] = @object[:da].to_i + d_r
64
+ end
65
+ if @object[:da].to_i > 30
66
+ m_r = (@object[:da].to_i / 30) - 1
67
+ @object[:da] -= m_r * 30
68
+ @object[:mo] = @object[:mo].to_i + m_r
69
+ end
70
+ if @object[:mo].to_i > 12
71
+ y_r = (@object[:mo].to_i / 12) - 1
72
+ @object[:mo] -= y_r * 12
73
+ @object[:yr] = @object[:yr].to_i + y_r
74
+ end
75
+ @object.to_s # site-effect
76
+ self
77
+ end
78
+
79
+ ##
80
+ # Returns `true` if the value adheres to the defined grammar of the
81
+ # datatype.
82
+ #
83
+ # Special case for date and dateTime, for which '0000' is not a valid year
84
+ #
85
+ # @return [Boolean]
86
+ # @since 0.2.1
87
+ def valid?
88
+ !!(value =~ GRAMMAR)
89
+ end
90
+
91
+ ##
92
+ # Returns the value as a string.
93
+ #
94
+ # @return [String]
95
+ def to_s
96
+ @string ||= begin
97
+ str = @object[:si] < 0 ? "-P" : "P"
98
+ str << "%dY" % @object[:yr].to_i if @object[:yr]
99
+ str << "%dM" % @object[:mo].to_i if @object[:mo]
100
+ str << "%dD" % @object[:da].to_i if @object[:da]
101
+ str << "T" if @object[:hr] || @object[:mi] || @object[:se]
102
+ str << "%dH" % @object[:hr].to_i if @object[:hr]
103
+ str << "%dM" % @object[:mi].to_i if @object[:mi]
104
+ str << "#{sec_str}S" if @object[:se]
105
+ end
106
+ end
107
+
108
+ def plural(v, str)
109
+ "#{v} #{str}#{v == 1 ? '' : 's'}" if v
110
+ end
111
+
112
+ ##
113
+ # Returns a human-readable value for the interval
114
+ def humanize(lang = :en)
115
+ @humanize ||= {}
116
+ @humanize[lang] ||= begin
117
+ # Just english, for now
118
+ ar = []
119
+ ar << plural(@object[:yr], "year")
120
+ ar << plural(@object[:mo], "month")
121
+ ar << plural(@object[:da], "day")
122
+ ar << plural(@object[:hr], "hour")
123
+ ar << plural(@object[:mi], "minute")
124
+ ar << plural(sec_str, "second") if @object[:se]
125
+ ar = ar.compact
126
+ last = ar.pop
127
+ first = ar.join(" ")
128
+ res = first.empty? ? last : "#{first} and #{last}"
129
+ @object[:si] < 0 ? "#{res} ago" : res
130
+ end
131
+ end
132
+
133
+ ##
134
+ # Equal compares as DateTime objects
135
+ def ==(other)
136
+ # If lexically invalid, use regular literal testing
137
+ return super unless self.valid?
138
+
139
+ case other
140
+ when Duration
141
+ return super unless other.valid?
142
+ self.to_f == something.to_f
143
+ when String
144
+ self.to_s(:xml) == something
145
+ when Numeric
146
+ self.to_f == something
147
+ when Literal::DateTime, Literal::Time, Literal::Date
148
+ false
149
+ else
150
+ super
151
+ end
152
+ end
153
+
154
+ # @return [Float]
155
+ def to_f
156
+ ( @object[:yr].to_i * 365 * 24 * 3600 +
157
+ @object[:mo].to_i * 30 * 24 * 3600 +
158
+ @object[:da].to_i * 24 * 3600 +
159
+ @object[:hr].to_i * 3600 +
160
+ @object[:mi].to_i * 60 +
161
+ @object[:se].to_f
162
+ ) * @object[:si]
163
+ end
164
+
165
+ # @return [Integer]
166
+ def to_i; Integer(self.to_f); end
167
+
168
+ private
169
+ # Reverse convert from XSD version of duration
170
+ # XSD allows -P1111Y22M33DT44H55M66.666S with any combination in regular order
171
+ # We assume 1M == 30D, but are out of spec in this regard
172
+ # We only output up to hours
173
+ #
174
+ # @param [String] value XSD formatted duration
175
+ # @return [Duration]
176
+ 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
188
+ end
189
+
190
+ 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
193
+ end
194
+ end # Duration
195
+ end; end # RDF::Literal
@@ -0,0 +1,191 @@
1
+ module RDF; class Literal
2
+ ##
3
+ # nonPositiveInteger is derived from integer by setting the value of maxInclusive to be 0. This results in
4
+ # the standard mathematical concept of the non-positive integers. The value space of nonPositiveInteger is the
5
+ # infinite set {...,-2,-1,0}. The base type of nonPositiveInteger is integer.
6
+ #
7
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#nonPositiveInteger
8
+ class NonPositiveInteger < Integer
9
+ DATATYPE = RDF::XSD.nonPositiveInteger
10
+ GRAMMAR = /^(?:[\+\-]?0)|(?:-\d+)$/.freeze
11
+
12
+ ##
13
+ # Returns `self` negated.
14
+ #
15
+ # @return [RDF::Literal::Numeric]
16
+ # @since 0.2.3
17
+ def -@
18
+ if object != 0
19
+ # XXX Raise error?
20
+ end
21
+ super
22
+ end
23
+
24
+ def valid?
25
+ super && @object <= 0
26
+ end
27
+ end
28
+
29
+ ##
30
+ # negativeInteger is derived from nonPositiveInteger by setting the value of maxInclusive to be -1. This
31
+ # results in the standard mathematical concept of the negative integers. The value space of negativeInteger is
32
+ # the infinite set {...,-2,-1}. The base type of negativeInteger is nonPositiveInteger.
33
+ #
34
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#negativeInteger
35
+ class NegativeInteger < NonPositiveInteger
36
+ GRAMMAR = /^\-\d+$/.freeze
37
+ DATATYPE = RDF::XSD.negativeInteger
38
+
39
+ ##
40
+ # Returns `self` negated.
41
+ #
42
+ # @return [RDF::Literal::Numeric]
43
+ # @since 0.2.3
44
+ def -@
45
+ if object != 0
46
+ # XXX Raise error?
47
+ end
48
+ self.class.new(-self.object)
49
+ end
50
+
51
+ def valid?
52
+ super && @object < 0
53
+ end
54
+ end
55
+
56
+ ##
57
+ # long is derived from integer by setting the value of maxInclusive to be 9223372036854775807
58
+ # and minInclusive to be -9223372036854775808.
59
+ #
60
+ # The base type of long is integer.
61
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#long
62
+ class Long < Integer
63
+ DATATYPE = RDF::XSD.long
64
+
65
+ def valid?
66
+ super && @object >= -9223372036854775808 && @object <= 9223372036854775807
67
+ end
68
+ end
69
+
70
+ ##
71
+ # int is derived from long by setting the value of maxInclusive to be 2147483647 and minInclusive to be
72
+ # -2147483648. The base type of int is long.
73
+ #
74
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#int
75
+ class Int < Long
76
+ DATATYPE = RDF::XSD.int
77
+
78
+ def valid?
79
+ super && @object >= -2147483648 && @object <= 2147483647
80
+ end
81
+ end
82
+
83
+ ##
84
+ # short is derived from int by setting the value of maxInclusive to be 32767 and minInclusive to be
85
+ # -32768. The base type of short is int.
86
+ #
87
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#short
88
+ class Short < Int
89
+ DATATYPE = RDF::XSD.short
90
+
91
+ def valid?
92
+ super && @object >= -32768 && @object <= 32767
93
+ end
94
+ end
95
+
96
+ ##
97
+ # byte is derived from short by setting the value of maxInclusive to be 127 and minInclusive to be -128.
98
+ # The base type of byte is short.
99
+ #
100
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#byte
101
+ class Byte < Short
102
+ DATATYPE = RDF::XSD.byte
103
+
104
+ def valid?
105
+ super && @object >= -128 && @object <= 127
106
+ end
107
+ end
108
+
109
+ ##
110
+ # nonNegativeInteger is derived from integer by setting the value of minInclusive to be 0. This results in
111
+ # the standard mathematical concept of the non-negative integers. The value space of nonNegativeInteger is the
112
+ # infinite set {0,1,2,...}. The base type of nonNegativeInteger is integer.
113
+ #
114
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#nonNegativeInteger
115
+ class NonNegativeInteger < Integer
116
+ GRAMMAR = /^(?:(?:[\+\-]?0)|(?:\+?\d+))$/.freeze
117
+ DATATYPE = RDF::XSD.nonNegativeInteger
118
+
119
+ def valid?
120
+ super && @object >= 0
121
+ end
122
+ end
123
+
124
+ ##
125
+ # positiveInteger is derived from nonNegativeInteger by setting the value of minInclusive to be 1. This
126
+ # results in the standard mathematical concept of the positive integer numbers. The value space of
127
+ # positiveInteger is the infinite set {1,2,...}. The base type of positiveInteger is nonNegativeInteger.
128
+ #
129
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#positiveInteger
130
+ class PositiveInteger < NonNegativeInteger
131
+ GRAMMAR = /^\+?\d+$/.freeze
132
+ DATATYPE = RDF::XSD.positiveInteger
133
+
134
+ def valid?
135
+ super && @object > 0
136
+ end
137
+ end
138
+
139
+ ##
140
+ # unsignedLong is derived from nonNegativeInteger by setting the value of maxInclusive to be
141
+ # 18446744073709551615. The base type of unsignedLong is nonNegativeInteger.
142
+ #
143
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#unsignedLong
144
+ class UnsignedLong < NonNegativeInteger
145
+ GRAMMAR = /^\d+$/.freeze
146
+ DATATYPE = RDF::XSD.unsignedLong
147
+
148
+ def valid?
149
+ super && @object >= 0 && @object <= 18446744073709551615
150
+ end
151
+ end
152
+
153
+ ##
154
+ # unsignedInt is derived from unsignedLong by setting the value of maxInclusive to be 4294967295. The base
155
+ # type of unsignedInt is unsignedLong.
156
+ #
157
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#unsignedInt
158
+ class UnsignedInt < UnsignedLong
159
+ DATATYPE = RDF::XSD.unsignedInt
160
+
161
+ def valid?
162
+ super && @object >= 0 && @object <= 4294967295
163
+ end
164
+ end
165
+
166
+ ##
167
+ # unsignedShort is derived from unsignedInt by setting the value of maxInclusive to be 65535. The base
168
+ # type of unsignedShort is unsignedInt.
169
+ #
170
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#unsignedShort
171
+ class UnsignedShort < UnsignedInt
172
+ DATATYPE = RDF::XSD.unsignedShort
173
+
174
+ def valid?
175
+ super && @object >= 0 && @object <= 65535
176
+ end
177
+ end
178
+
179
+ ##
180
+ # unsignedByte is derived from unsignedShort by setting the value of maxInclusive to be 255. The base
181
+ # type of unsignedByte is unsignedShort.
182
+ #
183
+ # @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#unsignedByte
184
+ class UnsignedByte < UnsignedShort
185
+ DATATYPE = RDF::XSD.unsignedByte
186
+
187
+ def valid?
188
+ super && @object >= 0 && @object <= 255
189
+ end
190
+ end
191
+ end; end #RDF::Literal
@@ -0,0 +1,18 @@
1
+ module RDF::XSD::VERSION
2
+ VERSION_FILE = File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..", "VERSION")
3
+ MAJOR, MINOR, TINY, EXTRA = File.read(VERSION_FILE).chop.split(".")
4
+
5
+ STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
6
+
7
+ ##
8
+ # @return [String]
9
+ def self.to_s() STRING end
10
+
11
+ ##
12
+ # @return [String]
13
+ def self.to_str() STRING end
14
+
15
+ ##
16
+ # @return [Array(Integer, Integer, Integer)]
17
+ def self.to_a() STRING.split(".") end
18
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdf-xsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gregg
9
+ - Kellogg
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-09-15 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rdf
17
+ requirement: &2165552680 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.3.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2165552680
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &2165552100 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2165552100
37
+ - !ruby/object:Gem::Dependency
38
+ name: rdf-spec
39
+ requirement: &2165551520 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: 0.3.2
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2165551520
48
+ - !ruby/object:Gem::Dependency
49
+ name: yard
50
+ requirement: &2165551000 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 0.6.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2165551000
59
+ description: Adds RDF::Literal subclasses for extended XSD datatypes
60
+ email: public-rdf-ruby@w3.org
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - AUTHORS
66
+ - README.markdown
67
+ - UNLICENSE
68
+ - VERSION
69
+ - lib/rdf/xsd/binary.rb
70
+ - lib/rdf/xsd/date.rb
71
+ - lib/rdf/xsd/double.rb
72
+ - lib/rdf/xsd/duration.rb
73
+ - lib/rdf/xsd/integer.rb
74
+ - lib/rdf/xsd/version.rb
75
+ - lib/rdf/xsd.rb
76
+ homepage: http://github.com/gkellogg/rdf-xsd
77
+ licenses:
78
+ - Public Domain
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: 1.8.1
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project: rdf-xsd
97
+ rubygems_version: 1.8.6
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Extended XSD Datatypes for RDF.rb
101
+ test_files: []