Class: TypedLiteral

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

Instance Attribute Summary collapse

Attributes inherited from Literal

#lang

Instance Method Summary collapse

Methods inherited from Literal

#to_ntriples

Constructor Details

#initialize(contents, encoding) ⇒ TypedLiteral

Returns a new instance of TypedLiteral.



44
45
46
47
48
49
50
51
52
# File 'lib/rena/literal.rb', line 44

def initialize(contents, encoding)
  @contents = contents
  @encoding = encoding
  if @encoding == "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"
    @xmlliteral = true
  else
    @xmlliteral = false
  end
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



43
44
45
# File 'lib/rena/literal.rb', line 43

def contents
  @contents
end

#encodingObject

Returns the value of attribute encoding.



43
44
45
# File 'lib/rena/literal.rb', line 43

def encoding
  @encoding
end

Instance Method Details

#==(obj) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/rena/literal.rb', line 54

def == (obj)
  if obj.class == TypedLiteral && obj.contents == @contents && obj.encoding == @encoding
    return true
  else
    return false
  end
end

#infer!Object



80
81
82
83
84
85
86
87
88
# File 'lib/rena/literal.rb', line 80

def infer!
  if @contents.class == Fixnum
    @encoding = "http://www.w3.org/2001/XMLSchema#int"
  elsif @contents.class == Float 
    @encoding = "http://www.w3.org/2001/XMLSchema#float"
  else
    @encoding = "http://www.w3.org/2001/XMLSchema#string"
  end
end

#to_n3Object



62
63
64
65
66
67
68
69
70
# File 'lib/rena/literal.rb', line 62

def to_n3
  if @encoding == "http://www.w3.org/2001/XMLSchema#int"
    out = @contents.to_s
  else
    out = "\"" + @contents.to_s + "\""
  end
  out += "^^<" + @encoding + ">" if @encoding != nil
  return out
end

#to_trixObject



72
73
74
# File 'lib/rena/literal.rb', line 72

def to_trix
  "<typedLiteral datatype=\"" + @encoding + "\">" + @contents + "</typedLiteral>"
end

#xmlliteral?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/rena/literal.rb', line 76

def xmlliteral?
  @xmlliteral
end