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

- (Object) compare_contents(a, b, same_lang)

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

- (Object) format_as_n3(content, lang)

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

- (Object) format_as_trix(content, lang)

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

- (Object) inspect



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

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

- (Object) to_s



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

def to_s
  ''
end

- (Object) xml_args(content, lang)

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