Module: DuckDB::Casting
- Included in:
- DuckDB
- Defined in:
- lib/duckdb/casting.rb
Instance Method Summary collapse
-
#cast(value, type) ⇒ Object
rubocop:disable Metrics/MethodLength.
Instance Method Details
#cast(value, type) ⇒ Object
rubocop:disable Metrics/MethodLength
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/duckdb/casting.rb', line 5 def cast(value, type) # rubocop:disable Metrics/MethodLength type = type.type if type.is_a?(DuckDB::LogicalType) case type when :integer, :bigint, :hugeint Integer(value) when :float, :double Float(value) when :varchar value.to_s when :timestamp (value) when :date cast_as_date(value) else raise ArgumentError, "Unsupported type: #{type} for value: #{value}" end end |