Class: Reddy::Literal::Null

Inherits:
Encoding show all
Defined in:
lib/reddy/literal.rb

Overview

The null encoding

Instance Attribute Summary

Attributes inherited from Encoding

#value

Instance Method Summary collapse

Methods inherited from Encoding

#==, coerce, #encode_contents, float, #hash, #initialize, integer, string, the_null_encoding, xmlliteral

Constructor Details

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

Instance Method Details

#compare_contents(a, b, same_lang) ⇒ Object

Compare literal contents, requiring languages to match



134
135
136
# File 'lib/reddy/literal.rb', line 134

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



110
111
112
# File 'lib/reddy/literal.rb', line 110

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

#format_as_trix(content, lang) ⇒ Object

Format content for TriX



115
116
117
118
119
120
121
# File 'lib/reddy/literal.rb', line 115

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

#inspectObject



138
139
140
# File 'lib/reddy/literal.rb', line 138

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

#to_sObject



105
106
107
# File 'lib/reddy/literal.rb', line 105

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"}]


127
128
129
130
131
# File 'lib/reddy/literal.rb', line 127

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