Module: RTM::Sugar::Occurrence::DynamicValue

Defined in:
rtm/lib/rtm/sugar/occurrence/dynamic_value.rb,
rtm/spec/rtm/sugar/occurrence/external_spec.rb,
rtm/spec/rtm/sugar/occurrence/dynamic_value_spec.rb

Instance Method Summary

Instance Method Details

- (Object) dynamic_value

Given the occurrence’s datatype this method returns the value of this occurrence cast as appropriate Ruby type.

:call-seq:

  dynamic_value -> Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'rtm/lib/rtm/sugar/occurrence/dynamic_value.rb', line 13

def dynamic_value
  value = self.value # a String
  case self.datatype.reference
  when RTM::PSI[:IRI]
    return topic_map.create_locator(value)
  when RTM::PSI[:Decimal]
    return value.to_f
  when RTM::PSI[:Double]
    return value.to_f
  when RTM::PSI[:Int]
    return value.to_i
  when RTM::PSI[:Integer]
    return value.to_i
  when RTM::PSI[:Float]
    return value.to_f
  when RTM::PSI[:Long]
    return value.to_i
  when RTM::PSI[:Date]
    return Date.parse(value)
  when RTM::PSI[:DateTime]
    return DateTime.parse(value)
  when RTM::PSI[:Time]
    return Time.parse(value)
  else
    return value
  end
end