Class: Reddy::Literal::Encoding

Inherits:
Object
  • Object
show all
Defined in:
lib/reddy/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.



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

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



54
55
56
# File 'lib/reddy/literal.rb', line 54

def value
  @value
end

Class Method Details

.coerce(string_or_nil) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/reddy/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/reddy/literal.rb', line 8

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

.integerObject



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

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

.stringObject



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

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

.the_null_encodingObject



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

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

Instance Method Details

#==(other) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/reddy/literal.rb', line 63

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

#format_as_n3(content) ⇒ Object



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

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

#format_as_trix(value) ⇒ Object



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

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

#hashObject



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

def hash
  @value.hash
end

#inspectObject



24
25
26
# File 'lib/reddy/literal.rb', line 24

def inspect
  to_s()
end

#should_quote?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/reddy/literal.rb', line 59

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

#to_sObject



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

def to_s
  @value
end

#xmlliteral?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/reddy/literal.rb', line 91

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