Class: Momomoto::Datatype::Time_without_time_zone
- Defined in:
- lib/momomoto/datatype/time_without_time_zone.rb
Overview
Represents the data type Time without time zone.
Direct Known Subclasses
Instance Method Summary collapse
-
#equal(a, b) ⇒ Object
Compares two values and returns true if equal or false otherwise.
-
#escape(value) ⇒ Object
Escapes
value
to be saved in database. -
#filter_set(value) ⇒ Object
Values are filtered by this function when being set.
Methods inherited from Base
#compile_rule, #default, #default_operator, #initialize, #not_null?, operator_sign
Constructor Details
This class inherits a constructor from Momomoto::Datatype::Base
Instance Method Details
#equal(a, b) ⇒ Object
Compares two values and returns true if equal or false otherwise. It is used to check if a row field has been changed so that only changed fields are written to database. Escapes before comparing.
14 15 16 |
# File 'lib/momomoto/datatype/time_without_time_zone.rb', line 14 def equal( a, b ) escape(a) == escape(b) end |
#escape(value) ⇒ Object
Escapes value
to be saved in database. Returns ‘NULL’ if value
is nil.
20 21 22 23 24 25 26 |
# File 'lib/momomoto/datatype/time_without_time_zone.rb', line 20 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_set(value) ⇒ Object
Values are filtered by this function when being set. Returns an instance of Time or nil if value
is nil or empty.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/momomoto/datatype/time_without_time_zone.rb', line 30 def filter_set( value ) case value when nil, '' then nil when ::Time then value when String then ::Time.parse( value ) else raise Error end rescue => e raise ConversionError, 'Error while parsing time' end |