Skip to content

Commit a35d255

Browse files
committed
Finish 3.0.3
2 parents ff729b0 + 03b6e2e commit a35d255

14 files changed

Lines changed: 73 additions & 27 deletions

File tree

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
language: ruby
22
bundler_args: --without debug
33
script: "bundle exec rspec spec"
4-
before_install: "gem update --system"
4+
before_install:
5+
- "gem update --system"
6+
- "gem install bundler"
57
env:
68
- CI=true
79
rvm:

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.2
1+
3.0.3

lib/rdf/cli.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ class Option
9292
# @return [String]
9393
attr_reader :description
9494

95+
# Default value for this option
96+
# @return [Object]
97+
attr_reader :default
98+
9599
# Potential values (for select or radio) or Ruby datatype
96100
# @return [Class, Array<String>]
97101
attr_reader :datatype
@@ -110,6 +114,7 @@ class Option
110114
# @param [Symbol] symbol
111115
# @param [Array<String>] on
112116
# @param [String] datatype
117+
# @param [Object] default
113118
# @param [String] control
114119
# @param [String] description
115120
# @param [[:optional, :disabled, :removed, :required]] use
@@ -118,10 +123,10 @@ class Option
118123
# @yieldparam [OptionParser] options (nil) optional OptionParser
119124
# @yieldreturn [Object] a possibly modified input value
120125
def initialize(symbol: nil, on: nil, datatype: nil, control: nil,
121-
description: nil, use: :optional, **options, &block)
126+
description: nil, use: :optional, default: nil, **options, &block)
122127
raise ArgumentError, "symbol is a required argument" unless symbol
123128
raise ArgumentError, "on is a required argument" unless on
124-
@symbol, @on, @datatype, @control, @description, @use, @callback = symbol.to_sym, Array(on), datatype, control, description, use, block
129+
@symbol, @on, @datatype, @control, @description, @use, @default, @callback = symbol.to_sym, Array(on), datatype, control, description, use, default, block
125130
end
126131

127132
def call(arg, options = {})
@@ -142,6 +147,7 @@ def to_hash
142147
{
143148
symbol: symbol,
144149
datatype: (datatype.is_a?(Class) ? datatype.name : datatype),
150+
default: default,
145151
control: control,
146152
description: description,
147153
use: use

lib/rdf/model/literal.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ def initialize(value, language: nil, datatype: nil, lexical: nil, validate: fals
170170
@language = language.to_s.downcase.to_sym if language
171171
@datatype = RDF::URI(datatype).freeze if datatype
172172
@datatype ||= self.class.const_get(:DATATYPE) if self.class.const_defined?(:DATATYPE)
173-
@datatype ||= @language ? RDF.langString : RDF::XSD.string
174-
raise ArgumentError, "datatype of rdf:langString requires a language" if !@language && @datatype == RDF::langString
173+
@datatype ||= @language ? RDF.langString : RDF::URI("http://www.w3.org/2001/XMLSchema#string")
175174
end
176175

177176
##
@@ -226,8 +225,8 @@ def compatible?(other)
226225
# * The arguments are plain literals with identical language tags
227226
# * The first argument is a plain literal with language tag and the second argument is a simple literal or literal typed as xsd:string
228227
has_language? ?
229-
(language == other.language || other.datatype == RDF::XSD.string) :
230-
other.datatype == RDF::XSD.string
228+
(language == other.language || other.datatype == RDF::URI("http://www.w3.org/2001/XMLSchema#string")) :
229+
other.datatype == RDF::URI("http://www.w3.org/2001/XMLSchema#string")
231230
end
232231

233232
##
@@ -317,7 +316,7 @@ def ==(other)
317316
# @return [Boolean] `true` or `false`
318317
# @see http://www.w3.org/TR/rdf-concepts/#dfn-plain-literal
319318
def plain?
320-
[RDF.langString, RDF::XSD.string].include?(datatype)
319+
[RDF.langString, RDF::URI("http://www.w3.org/2001/XMLSchema#string")].include?(datatype)
321320
end
322321

323322
##
@@ -327,7 +326,7 @@ def plain?
327326
# @return [Boolean] `true` or `false`
328327
# @see http://www.w3.org/TR/sparql11-query/#simple_literal
329328
def simple?
330-
datatype == RDF::XSD.string
329+
datatype == RDF::URI("http://www.w3.org/2001/XMLSchema#string")
331330
end
332331

333332
##
@@ -361,6 +360,8 @@ def has_datatype?
361360
# @return [Boolean] `true` or `false`
362361
# @since 0.2.1
363362
def valid?
363+
return false if language? && language.to_s !~ /^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/
364+
return false if datatype? && datatype.invalid?
364365
grammar = self.class.const_get(:GRAMMAR) rescue nil
365366
grammar.nil? || !!(value =~ grammar)
366367
end
@@ -487,15 +488,15 @@ def inspect
487488
def method_missing(name, *args)
488489
case name
489490
when :to_str
490-
return to_s if @datatype == RDF.langString || @datatype == RDF::XSD.string
491+
return to_s if @datatype == RDF.langString || @datatype == RDF::URI("http://www.w3.org/2001/XMLSchema#string")
491492
end
492493
super
493494
end
494495

495496
def respond_to_missing?(name, include_private = false)
496497
case name
497498
when :to_str
498-
return true if @datatype == RDF.langString || @datatype == RDF::XSD.string
499+
return true if @datatype == RDF.langString || @datatype == RDF::URI("http://www.w3.org/2001/XMLSchema#string")
499500
end
500501
super
501502
end

lib/rdf/model/literal/boolean.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module RDF; class Literal
55
# @see http://www.w3.org/TR/xmlschema11-2/#boolean
66
# @since 0.2.1
77
class Boolean < Literal
8-
DATATYPE = RDF::XSD.boolean
8+
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#boolean")
99
GRAMMAR = /^(true|false|1|0)$/.freeze
1010
TRUES = %w(true 1).freeze
1111
FALSES = %w(false 0).freeze

lib/rdf/model/literal/date.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module RDF; class Literal
55
# @see http://www.w3.org/TR/xmlschema11-2/#date
66
# @since 0.2.1
77
class Date < Literal
8-
DATATYPE = RDF::XSD.date
8+
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#date")
99
GRAMMAR = %r(\A(-?\d{4}-\d{2}-\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)?\Z).freeze
1010
FORMAT = '%Y-%m-%d'.freeze
1111

lib/rdf/model/literal/datetime.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module RDF; class Literal
55
# @see http://www.w3.org/TR/xmlschema11-2/#dateTime#boolean
66
# @since 0.2.1
77
class DateTime < Literal
8-
DATATYPE = RDF::XSD.dateTime
8+
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#dateTime")
99
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
1010
FORMAT = '%Y-%m-%dT%H:%M:%S%:z'.freeze
1111

@@ -57,14 +57,14 @@ def tz
5757
# @return [RDF::Literal]
5858
def timezone
5959
if tz == 'Z'
60-
RDF::Literal("PT0S", datatype: RDF::XSD.dayTimeDuration)
60+
RDF::Literal("PT0S", datatype: RDF::URI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))
6161
elsif md = tz.to_s.match(/^([+-])?(\d+):(\d+)?$/)
6262
plus_minus, hour, min = md[1,3]
6363
plus_minus = nil unless plus_minus == "-"
6464
hour = hour.to_i
6565
min = min.to_i
6666
res = "#{plus_minus}PT#{hour}H#{"#{min}M" if min > 0}"
67-
RDF::Literal(res, datatype: RDF::XSD.dayTimeDuration)
67+
RDF::Literal(res, datatype: RDF::URI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))
6868
end
6969
end
7070

lib/rdf/model/literal/decimal.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module RDF; class Literal
1111
# @see http://www.w3.org/TR/xmlschema11-2/#decimal
1212
# @since 0.2.1
1313
class Decimal < Numeric
14-
DATATYPE = RDF::XSD.decimal
14+
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#decimal")
1515
GRAMMAR = /^[\+\-]?\d+(\.\d*)?$/.freeze
1616

1717
##

lib/rdf/model/literal/double.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module RDF; class Literal
1111
# @see http://www.w3.org/TR/xmlschema11-2/#double
1212
# @since 0.2.1
1313
class Double < Numeric
14-
DATATYPE = RDF::XSD.double
14+
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#double")
1515
GRAMMAR = /^(?:NaN|\-?INF|[+\-]?(?:\d+(:?\.\d*)?|\.\d+)(?:[eE][\+\-]?\d+)?)$/.freeze
1616

1717
##

lib/rdf/model/literal/integer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module RDF; class Literal
1212
# @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#integer
1313
# @since 0.2.1
1414
class Integer < Decimal
15-
DATATYPE = RDF::XSD.integer
15+
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#integer")
1616
GRAMMAR = /^[\+\-]?\d+$/.freeze
1717

1818
##

0 commit comments

Comments
 (0)