Skip to content
Browse files

Added RDF::Literal::String

  • Loading branch information...
1 parent a710125 commit 8587975559e7666a1d8bdb613109a353d3129037 @gkellogg gkellogg committed Nov 26, 2012
Showing with 38 additions and 0 deletions.
  1. +38 −0 lib/rdf/model/literal/string.rb
View
38 lib/rdf/model/literal/string.rb
@@ -0,0 +1,38 @@
+module RDF; class Literal
+ ##
+ # A String literal.
+ #
+ # @see http://www.w3.org/TR/xmlschema-2/#string
+ # @since 0.3.11
+ class String < Literal
+ DATATYPE = XSD.string
+ GRAMMAR = nil
+
+ ##
+ # @param [Object] value
+ # @option options [String] :lexical (nil)
+ def initialize(value, options = {})
+ @datatype = options[:datatype] || self.class.const_get(:DATATYPE)
+ @string = options[:lexical] if options.has_key?(:lexical)
+ @string ||= value if value.is_a?(String)
+ @object = value.to_s
+ end
+
+ ##
+ # Converts this literal into its canonical lexical representation.
+ #
+ # @return [RDF::Literal] `self`
+ # @see http://www.w3.org/TR/xml-exc-c14n/
+ def canonicalize!
+ self
+ end
+
+ ##
+ # Returns the value as a string.
+ #
+ # @return [String]
+ def to_s
+ @string || @object
+ end
+ end # XML
+end; end # RDF::Literal

0 comments on commit 8587975

Please sign in to comment.
Something went wrong with that request. Please try again.