Class: RdfContext::Literal::Null

Inherits:
Encoding
  • Object
show all
Defined in:
lib/rdf_context/literal.rb

Overview

The null encoding

Instance Attribute Summary

Attributes inherited from Encoding

#value

Instance Method Summary collapse

Methods inherited from Encoding

#==, boolean, coerce, date, datetime, double, duration, #encode_contents, float, #hash, #initialize, integer, string, the_null_encoding, time, #valid?, xmlliteral

Constructor Details

This class inherits a constructor from RdfContext::Literal::Encoding

Instance Method Details

#compare_contents(a, b, same_lang) ⇒ Object

Compare literal contents, requiring languages to match



205
206
207
# File 'lib/rdf_context/literal.rb', line 205

def compare_contents(a, b, same_lang)
  a == b && same_lang
end

#format_as_n3(content, lang) ⇒ Object

Format content for n3/N-Triples. Quote an RDF-escape and include language



181
182
183
# File 'lib/rdf_context/literal.rb', line 181

def format_as_n3(content, lang)
  "\"#{content.to_s.rdf_escape}\"" + (lang ? "@#{lang}" : "")
end

#format_as_trix(content, lang) ⇒ Object

Format content for TriX



186
187
188
189
190
191
192
# File 'lib/rdf_context/literal.rb', line 186

def format_as_trix(content, lang)
  if lang
    "<plainLiteral xml:lang=\"#{lang}\"\>#{content}</plainLiteral>"
  else
    "<plainLiteral>#{content}</plainLiteral>"
  end
end

#inspectObject



209
210
211
# File 'lib/rdf_context/literal.rb', line 209

def inspect
  "<Literal::Encoding::Null>"
end

#to_sObject



176
177
178
# File 'lib/rdf_context/literal.rb', line 176

def to_s
  ''
end

#xml_args(content, lang) ⇒ Object

Return content and hash appropriate for encoding in XML

Example

Encoding.the_null_encoding.xml_args("foo", "en-US") => ["foo", {"xml:lang" => "en-US"}]


198
199
200
201
202
# File 'lib/rdf_context/literal.rb', line 198

def xml_args(content, lang)
  hash = {}
  hash["xml:lang"] = lang if lang
  [content, hash]
end