Class: Lutaml::Rdf::Literal
- Inherits:
-
Object
- Object
- Lutaml::Rdf::Literal
- Includes:
- LanguageTagged
- Defined in:
- lib/lutaml/rdf/literal.rb
Instance Attribute Summary collapse
-
#datatype ⇒ Object
readonly
Returns the value of attribute datatype.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(value, datatype: nil, language: nil) ⇒ Literal
constructor
A new instance of Literal.
- #to_jsonld_term ⇒ Object
- #to_turtle ⇒ Object
Methods included from LanguageTagged
Constructor Details
#initialize(value, datatype: nil, language: nil) ⇒ Literal
Returns a new instance of Literal.
10 11 12 13 14 |
# File 'lib/lutaml/rdf/literal.rb', line 10 def initialize(value, datatype: nil, language: nil) @value = value @datatype = datatype @language = language end |
Instance Attribute Details
#datatype ⇒ Object (readonly)
Returns the value of attribute datatype.
8 9 10 |
# File 'lib/lutaml/rdf/literal.rb', line 8 def datatype @datatype end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
8 9 10 |
# File 'lib/lutaml/rdf/literal.rb', line 8 def language @language end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/lutaml/rdf/literal.rb', line 8 def value @value end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
37 38 39 40 41 42 |
# File 'lib/lutaml/rdf/literal.rb', line 37 def ==(other) other.is_a?(self.class) && value == other.value && datatype == other.datatype && language == other.language end |
#hash ⇒ Object
45 46 47 |
# File 'lib/lutaml/rdf/literal.rb', line 45 def hash [value, datatype, language].hash end |
#to_jsonld_term ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/lutaml/rdf/literal.rb', line 27 def to_jsonld_term if language { "@value" => value, "@language" => language } elsif datatype { "@value" => value, "@type" => datatype.to_s } else value end end |
#to_turtle ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lutaml/rdf/literal.rb', line 16 def to_turtle escaped = escape_turtle(value.to_s) if language "#{escaped}@#{language}" elsif datatype "#{escaped}^^<#{datatype}>" else escaped end end |