Module: Literal

Included in:
Date, DateTime, FalseClass, Float, Integer, LocalizedString, String, Time, TrueClass
Defined in:
lib/active_rdf/objectmanager/literal.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.typed(value, type) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_rdf/objectmanager/literal.rb', line 21

def self.typed(value, type)
  case type
  when XSD::string
    String.new(value)
  when XSD::date
    DateTime.parse(value)
  when XSD::boolean
    value == 'true' or value == 1
  when XSD::integer
    value.to_i
  when XSD::double
    value.to_f
  end
end

Instance Method Details

#to_ntripleObject



36
37
38
39
40
41
42
# File 'lib/active_rdf/objectmanager/literal.rb', line 36

def to_ntriple
  if $activerdf_without_xsdtype
    "\"#{to_s}\""
  else
    "\"#{to_s}\"^^#{xsd_type}"
  end
end

#xsd_typeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/active_rdf/objectmanager/literal.rb', line 6

def xsd_type
  case self
  when String
    XSD::string
  when Integer
    XSD::integer
  when Float
    XSD::double
  when TrueClass, FalseClass
    XSD::boolean
  when DateTime, Date, Time
    XSD::date
  end
end