Class: Rfm::Metadata::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/fm_store/ext/field.rb

Instance Method Summary collapse

Instance Method Details

#coerce(value, resultset) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fm_store/ext/field.rb', line 4

def coerce(value, resultset)
  return nil if (value.nil? || value.empty?)
  case self.result
  when "text"      then value
  when "number"    then BigDecimal.new(value)
  when "date"      then Date.strptime(value, resultset.date_format)
  when "time"      then DateTime.strptime("1/1/-4712 #{value}", "%m/%d/%Y #{resultset.time_format}")
  when "timestamp" then DateTime.strptime(value, resultset.timestamp_format)
  when "container" then URI.parse("#{resultset.server.scheme}://#{resultset.server.host_name}:#{resultset.server.port}#{value}")
  else nil
  end
rescue
  nil
end