Module: Believer::Values
- Included in:
- Insert, WhereClause
- Defined in:
- lib/believer/values.rb
Constant Summary collapse
- TIMESTAMP_FORMAT =
'%Y-%m-%d %H:%M:%S%z'
Instance Method Summary collapse
- #convert_to_boolean(v) ⇒ Object
- #convert_to_float(v) ⇒ Object
- #convert_to_integer(v) ⇒ Object
- #convert_to_time(v) ⇒ Object
- #to_cql_literal(value) ⇒ Object
Instance Method Details
#convert_to_boolean(v) ⇒ Object
26 27 28 29 |
# File 'lib/believer/values.rb', line 26 def convert_to_boolean(v) return v.to_bool if v.respond_to?(:to_bool) nil end |
#convert_to_float(v) ⇒ Object
21 22 23 24 |
# File 'lib/believer/values.rb', line 21 def convert_to_float(v) return v.to_f unless v.nil? nil end |
#convert_to_integer(v) ⇒ Object
16 17 18 19 |
# File 'lib/believer/values.rb', line 16 def convert_to_integer(v) return v.to_i unless v.nil? nil end |
#convert_to_time(v) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/believer/values.rb', line 31 def convert_to_time(v) return nil if v.nil? return v if v.is_a?(Time) return Time.parse(v) if v.is_a?(String) Time.at(v.to_i) end |
#to_cql_literal(value) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/believer/values.rb', line 7 def to_cql_literal(value) return 'NULL' if value.nil? return "'#{value}'" if value.is_a?(String) return "#{value}" if value.is_a?(Numeric) return "'#{value.strftime(TIMESTAMP_FORMAT)}'" if value.is_a?(Time) || value.is_a?(DateTime) #return "#{value.to_i * 1000}" if value.is_a?(Time) || value.is_a?(DateTime) return nil end |