Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

In Literal sub-classes, ensure that DATATYPE constant comes from actu…

…al class used.

Remove special datatype logic in Literal#object.
  • Loading branch information...
commit c1ebb4d8fdd740e4825eca26d048c3d580c8fc1d 1 parent c35866e
Gregg Kellogg gkellogg authored
25 lib/rdf/model/literal.rb
View
@@ -139,30 +139,7 @@ def value
##
# @return [Object]
def object
- @object || case datatype
- when XSD.string, nil
- value
- when XSD.boolean
- %w(true 1).include?(value)
- when XSD.integer, XSD.long, XSD.int, XSD.short, XSD.byte
- value.to_i
- when XSD.double, XSD.float
- value.to_f
- when XSD.decimal
- ::BigDecimal.new(value)
- when XSD.date
- ::Date.parse(value)
- when XSD.dateTime
- ::DateTime.parse(value)
- when XSD.time
- ::Time.parse(value)
- when XSD.nonPositiveInteger, XSD.negativeInteger
- value.to_i
- when XSD.nonNegativeInteger, XSD.positiveInteger
- value.to_i
- when XSD.unsignedLong, XSD.unsignedInt, XSD.unsignedShort, XSD.unsignedByte
- value.to_i
- end
+ defined?(@object) ? @object : value
end
##
2  lib/rdf/model/literal/boolean.rb
View
@@ -14,7 +14,7 @@ class Boolean < Literal
# @param [Boolean] value
# @option options [String] :lexical (nil)
def initialize(value, options = {})
- @datatype = RDF::URI(options[:datatype] || DATATYPE)
+ @datatype = RDF::URI(options[:datatype] || self.class.const_get(:DATATYPE))
@string = options[:lexical] if options.has_key?(:lexical)
@string ||= value if value.is_a?(String)
@object = case
2  lib/rdf/model/literal/date.rb
View
@@ -13,7 +13,7 @@ class Date < Literal
# @param [Date] value
# @option options [String] :lexical (nil)
def initialize(value, options = {})
- @datatype = RDF::URI(options[:datatype] || DATATYPE)
+ @datatype = RDF::URI(options[:datatype] || self.class.const_get(:DATATYPE))
@string = options[:lexical] if options.has_key?(:lexical)
@string ||= value if value.is_a?(String)
@object = case
2  lib/rdf/model/literal/datetime.rb
View
@@ -12,7 +12,7 @@ class DateTime < Literal
# @param [DateTime] value
# @option options [String] :lexical (nil)
def initialize(value, options = {})
- @datatype = RDF::URI(options[:datatype] || DATATYPE)
+ @datatype = RDF::URI(options[:datatype] || self.class.const_get(:DATATYPE))
@string = options[:lexical] if options.has_key?(:lexical)
@string ||= value if value.is_a?(String)
@object = case
2  lib/rdf/model/literal/decimal.rb
View
@@ -18,7 +18,7 @@ class Decimal < Numeric
# @param [BigDecimal] value
# @option options [String] :lexical (nil)
def initialize(value, options = {})
- @datatype = RDF::URI(options[:datatype] || DATATYPE)
+ @datatype = RDF::URI(options[:datatype] || self.class.const_get(:DATATYPE))
@string = options[:lexical] if options.has_key?(:lexical)
@string ||= value if value.is_a?(String)
@object = case
2  lib/rdf/model/literal/double.rb
View
@@ -18,7 +18,7 @@ class Double < Numeric
# @param [Float, #to_f] value
# @option options [String] :lexical (nil)
def initialize(value, options = {})
- @datatype = RDF::URI(options[:datatype] || DATATYPE)
+ @datatype = RDF::URI(options[:datatype] || self.class.const_get(:DATATYPE))
@string = options[:lexical] if options.has_key?(:lexical)
@string ||= value if value.is_a?(String)
@object = case
2  lib/rdf/model/literal/integer.rb
View
@@ -19,7 +19,7 @@ class Integer < Decimal
# @param [Integer, #to_i] value
# @option options [String] :lexical (nil)
def initialize(value, options = {})
- @datatype = RDF::URI(options[:datatype] || DATATYPE)
+ @datatype = RDF::URI(options[:datatype] || self.class.const_get(:DATATYPE))
@string = options[:lexical] if options.has_key?(:lexical)
@string ||= value if value.is_a?(String)
@object = case
2  lib/rdf/model/literal/time.rb
View
@@ -17,7 +17,7 @@ class Time < Literal
# @param [Time] value
# @option options [String] :lexical (nil)
def initialize(value, options = {})
- @datatype = RDF::URI(options[:datatype] || DATATYPE)
+ @datatype = RDF::URI(options[:datatype] || self.class.const_get(:DATATYPE))
@string = options[:lexical] if options.has_key?(:lexical)
@string ||= value if value.is_a?(String)
@object = case
2  lib/rdf/model/literal/token.rb
View
@@ -12,7 +12,7 @@ class Token < Literal
# @param [Symbol, #to_s] value
# @option options [String] :lexical (nil)
def initialize(value, options = {})
- @datatype = RDF::URI(options[:datatype] || DATATYPE)
+ @datatype = RDF::URI(options[:datatype] || self.class.const_get(:DATATYPE))
@string = options[:lexical] if options.has_key?(:lexical)
@string ||= value if value.is_a?(String)
@object = value.is_a?(Symbol) ? value : value.to_s
2  lib/rdf/model/literal/xml.rb
View
@@ -13,7 +13,7 @@ class XML < Literal
# @param [Object] value
# @option options [String] :lexical (nil)
def initialize(value, options = {})
- @datatype = options[:datatype] || DATATYPE
+ @datatype = options[:datatype] || self.class.const_get(:DATATYPE)
@string = options[:lexical] if options.has_key?(:lexical)
@object = value # TODO: parse XML string using REXML
end
4 spec/model_literal_spec.rb
View
@@ -427,9 +427,9 @@ def self.literals(*selector)
literal(:xml_def_ns) => %("foo <sup xmlns=\\"http://purl.org/dc/terms/\\">bar</sup> baz!"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>),
literal(:xml_ns2) => %(fixme),
}.each_pair do |args, rep|
- it "returns n3 rep for #{args.inspect}" do
+ it "returns xml representation for #{args.inspect}" do
literal = RDF::Literal.new(*args)
- pending {literal.to_s.should == rep}
+ pending("XMLLiteral support") {literal.to_s.should == rep}
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.