Class: Momomoto::Datatype::Interval

Inherits:
Time_without_time_zone show all
Defined in:
lib/momomoto/datatype/interval.rb

Overview

This class represents the data type Interval.

Instance Method Summary collapse

Methods inherited from Time_without_time_zone

#equal

Methods inherited from Base

#compile_rule, #default, #default_operator, #equal, #initialize, #not_null?, operator_sign

Constructor Details

This class inherits a constructor from Momomoto::Datatype::Base

Instance Method Details

#escape(value) ⇒ Object

Escapes value before storing to database. value can be either

nil, resulting in 'NULL',
String, which is escaped using Database#quote,
or some Date-like format


12
13
14
15
16
17
18
# File 'lib/momomoto/datatype/interval.rb', line 12

def escape( value )
  case value
    when nil then 'NULL'
    when String then Database.quote(value)
    else Database.quote(value.strftime('%H:%M:%S'))
  end
end

#filter_get(value) ⇒ Object

Values are filtered by this method when getting them from database. Returns an instance of TimeInterval or nil if value is nil or empty. Raises ConversionError if the given value cannot be parsed.



24
25
26
27
28
29
30
31
32
33
# File 'lib/momomoto/datatype/interval.rb', line 24

def filter_get( value )
  case value
    when nil, '' then nil
    when ::TimeInterval then value
    when String then ::TimeInterval.parse( value )
    else raise Error
  end
 rescue => e
  raise ConversionError, "Error while parsing interval (#{e.message})"
end

#filter_set(value) ⇒ Object

Values are filtered by this function when being set. See Interval#filter_get



37
38
39
# File 'lib/momomoto/datatype/interval.rb', line 37

def filter_set( value )
  filter_get( value )
end