Class: Literal

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

Direct Known Subclasses

TypedLiteral

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents, lang = nil) ⇒ Literal

Returns a new instance of Literal.



3
4
5
6
7
8
# File 'lib/rena/literal.rb', line 3

def initialize(contents, lang = nil)
  @contents = contents
  if lang != nil && lang != false
    @lang = lang.downcase
  end
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



2
3
4
# File 'lib/rena/literal.rb', line 2

def contents
  @contents
end

#langObject

Returns the value of attribute lang.



2
3
4
# File 'lib/rena/literal.rb', line 2

def lang
  @lang
end

Instance Method Details

#==(obj) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/rena/literal.rb', line 10

def == (obj)
  if obj.class == Literal && obj.contents == @contents && (obj.lang == @lang || (obj.lang == nil && @lang == nil))
    true
  else
    false
  end
end

#to_n3Object



18
19
20
21
22
23
# File 'lib/rena/literal.rb', line 18

def to_n3
  out = "\"" + @contents + "\""
  out += "@" + @lang if @lang != nil
  out += "^^" + @encoding if @encoding != nil
  return out
end

#to_ntriplesObject



25
26
27
# File 'lib/rena/literal.rb', line 25

def to_ntriples
  return self.to_n3
end

#to_trixObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/rena/literal.rb', line 29

def to_trix
  if @lang != nil && @lang != false
    out = "<plainLiteral xml:lang=\"" + @lang + "\">"
  else
    out = "<plainLiteral>"
  end
  out += @contents
  out += "</plainLiteral>"
  return out
end