lib/duckdb/appender.rb in duckdb-0.2.9.0 vs lib/duckdb/appender.rb in duckdb-0.3.1.0
- old
+ new
@@ -61,22 +61,20 @@
# # appender.append_date('2021-10-10')
# appender.end_row
# appender.flush
#
def append_date(value)
- case value
- when Date, Time
- date = value
- when String
- begin
- date = Date.parse(value)
- rescue
- raise(ArgumentError, "Cannot parse argument `#{value}` to Date.")
- end
- else
- raise(ArgumentError, "Argument `#{value}` must be Date, Time or String.")
- end
+ date = case value
+ when Date, Time
+ value
+ else
+ begin
+ Date.parse(value)
+ rescue
+ raise(ArgumentError, "Cannot parse argument `#{value}` to Date.")
+ end
+ end
_append_date(date.year, date.month, date.day)
end
#
@@ -93,22 +91,20 @@
# # appender.append_time('01:01:01')
# appender.end_row
# appender.flush
#
def append_time(value)
- case value
- when Time
- time = value
- when String
- begin
- time = Time.parse(value)
- rescue
- raise(ArgumentError, "Cannot parse argument `#{value}` to Time.")
- end
- else
- raise(ArgumentError, "Argument `#{value}` must be Time or String.")
- end
+ time = case value
+ when Time
+ value
+ else
+ begin
+ Time.parse(value)
+ rescue
+ raise(ArgumentError, "Cannot parse argument `#{value}` to Time.")
+ end
+ end
_append_time(time.hour, time.min, time.sec, time.usec)
end
#
@@ -126,23 +122,22 @@
# # appender.append_time('2021-08-01 01:01:01')
# appender.end_row
# appender.flush
#
def append_timestamp(value)
- case value
- when Time
- time = value
- when Date
- time = value.to_time
- when String
- begin
- time = Time.parse(value)
- rescue
- raise(ArgumentError, "Cannot parse argument `#{value.class} #{value}` to Time.")
- end
- else
- raise(ArgumentError, "Argument `#{value.class} #{value}` must be Time or Date or String.")
- end
+ time = case value
+ when Time
+ value
+ when Date
+ value.to_time
+ else
+ begin
+ Time.parse(value)
+ rescue
+ raise(ArgumentError, "Cannot parse argument `#{value}` to Time or Date.")
+ end
+ end
+
_append_timestamp(time.year, time.month, time.day, time.hour, time.min, time.sec, time.nsec / 1000)
end
#
# appends interval.