Class: RDF::Literal
- Inherits:
-
Object
- Object
- RDF::Literal
- Includes:
- N3::Terminals
- Defined in:
- lib/rdf/n3/extensions.rb
Constant Summary
Constants included from N3::Terminals
N3::Terminals::ANON, N3::Terminals::BASE, N3::Terminals::BLANK_NODE_LABEL, N3::Terminals::DECIMAL, N3::Terminals::DOUBLE, N3::Terminals::ECHAR, N3::Terminals::ESCAPE_CHAR4, N3::Terminals::ESCAPE_CHAR8, N3::Terminals::EXPONENT, N3::Terminals::INTEGER, N3::Terminals::IPLSTART, N3::Terminals::IRIREF, N3::Terminals::IRI_RANGE, N3::Terminals::LANGTAG, N3::Terminals::PERCENT, N3::Terminals::PLX, N3::Terminals::PNAME_LN, N3::Terminals::PNAME_NS, N3::Terminals::PN_CHARS, N3::Terminals::PN_CHARS_BASE, N3::Terminals::PN_CHARS_BODY, N3::Terminals::PN_CHARS_U, N3::Terminals::PN_LOCAL, N3::Terminals::PN_LOCAL_BODY, N3::Terminals::PN_LOCAL_ESC, N3::Terminals::PN_PREFIX, N3::Terminals::PREFIX, N3::Terminals::QUICK_VAR_NAME, N3::Terminals::STRING_LITERAL_LONG_QUOTE, N3::Terminals::STRING_LITERAL_LONG_SINGLE_QUOTE, N3::Terminals::STRING_LITERAL_QUOTE, N3::Terminals::STRING_LITERAL_SINGLE_QUOTE, N3::Terminals::UCHAR, N3::Terminals::U_CHARS1, N3::Terminals::U_CHARS2, N3::Terminals::WS
Instance Method Summary collapse
-
#as_datetime ⇒ RDF::Literal::DateTime
Parse the value as a dateTime literal, or return now.
-
#as_number ⇒ RDF::Literal::Numeric
Parse the value as a numeric literal, or return 0.
Instance Method Details
#as_datetime ⇒ RDF::Literal::DateTime
Parse the value as a dateTime literal, or return now.
105 106 107 108 109 110 111 112 113 |
# File 'lib/rdf/n3/extensions.rb', line 105 def as_datetime return self if is_a?(RDF::Literal::DateTime) mvalue = value mvalue = "#{mvalue}-01" if mvalue.match?(%r(^\d{4}$)) mvalue = "#{mvalue}-01" if mvalue.match?(%r(^\d{4}-\d{2}$)) RDF::Literal::DateTime.new(::DateTime.iso8601(mvalue), lexical: value) rescue RDF::Literal(0) end |
#as_number ⇒ RDF::Literal::Numeric
Parse the value as a numeric literal, or return 0.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rdf/n3/extensions.rb', line 90 def as_number return self if self.is_a?(RDF::Literal::Numeric) case value when DOUBLE then RDF::Literal::Double.new(value) when DECIMAL then RDF::Literal::Decimal.new(value) when INTEGER then RDF::Literal::Integer.new(value) else RDF::Literal(0) end end |