Class: Rena::Literal::Encoding

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

Direct Known Subclasses

Language

Defined Under Namespace

Classes: Null

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Encoding

Returns a new instance of Encoding.



51
52
53
# File 'lib/rena/literal.rb', line 51

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



50
51
52
# File 'lib/rena/literal.rb', line 50

def value
  @value
end

Class Method Details

.coerce(string_or_nil) ⇒ Object



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

def self.coerce(string_or_nil)
  if string_or_nil.nil? || string_or_nil == ''
    the_null_encoding
  else
    new string_or_nil
  end
end

.floatObject



8
9
10
# File 'lib/rena/literal.rb', line 8

def self.float
  @float ||= coerce "http://www.w3.org/2001/XMLSchema#float"
end

.integerObject



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

def self.integer
  @integer ||= coerce "http://www.w3.org/2001/XMLSchema#int"
end

.stringObject



12
13
14
# File 'lib/rena/literal.rb', line 12

def self.string
  @string ||= coerce "http://www.w3.org/2001/XMLSchema#string"
end

.the_null_encodingObject



46
47
48
# File 'lib/rena/literal.rb', line 46

def self.the_null_encoding
  @the_null_encoding ||= Null.new
end

Instance Method Details

#==(other) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/rena/literal.rb', line 59

def ==(other)
  case other
  when String
    other == @value
  when self.class
    other.value == @value
  else
    false
  end
end

#format_as_n3(content) ⇒ Object



78
79
80
81
# File 'lib/rena/literal.rb', line 78

def format_as_n3(content)
  quoted_content = should_quote? ? "\"#{content}\"" : content
  "#{quoted_content}^^<#{value}>"
end

#format_as_trix(value) ⇒ Object



83
84
85
# File 'lib/rena/literal.rb', line 83

def format_as_trix(value)
  "<typedLiteral datatype=\"#{@value}\">#{value}</typedLiteral>"
end

#hashObject



70
71
72
# File 'lib/rena/literal.rb', line 70

def hash
  @value.hash
end

#should_quote?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/rena/literal.rb', line 55

def should_quote?
  @value != self.class.integer.to_s
end

#to_sObject



74
75
76
# File 'lib/rena/literal.rb', line 74

def to_s
  @value
end

#xmlliteral?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/rena/literal.rb', line 87

def xmlliteral?
  @value == "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"
end