Module: JdbcSpec::HSQLDB::Column
- Defined in:
- lib/jdbc_adapter/jdbc_hsqldb.rb
Instance Method Summary collapse
- #cast_to_date_or_time(value) ⇒ Object
- #cast_to_time(value) ⇒ Object
- #guess_date_or_time(value) ⇒ Object
- #type_cast(value) ⇒ Object
Instance Method Details
#cast_to_date_or_time(value) ⇒ Object
43 44 45 46 47 |
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 43 def cast_to_date_or_time(value) return value if value.is_a? Date return nil if value.blank? guess_date_or_time((value.is_a? Time) ? value : cast_to_time(value)) end |
#cast_to_time(value) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 49 def cast_to_time(value) return value if value.is_a? Time time_array = ParseDate.parsedate value time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1; Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil end |
#guess_date_or_time(value) ⇒ Object
56 57 58 59 |
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 56 def guess_date_or_time(value) (value.hour == 0 and value.min == 0 and value.sec == 0) ? Date.new(value.year, value.month, value.day) : value end |
#type_cast(value) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 29 def type_cast(value) return nil if value.nil? || value =~ /^\s*null\s*$/i case type when :string then value when :integer then defined?(value.to_i) ? value.to_i : (value ? 1 : 0) when :primary_key then defined?(value.to_i) ? value.to_i : (value ? 1 : 0) when :float then value.to_f when :datetime then cast_to_date_or_time(value) when :timestamp then cast_to_time(value) when :binary then value.scan(/[0-9A-Fa-f]{2}/).collect {|v| v.to_i(16)}.pack("C*") when :time then cast_to_time(value) else value end end |