Skip to content

Commit

Permalink
parse numbers based on column type
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpeterson committed Nov 21, 2024
1 parent acc1a6e commit 6b9ef9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 4 additions & 6 deletions lib/cafe_car/param_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,15 @@ def value(v)
when /\.\./
a, b = v.split('..').map(&:presence).map { value(_1) }
a..b
when /\A(\d*\.)?\d+\z/
v.try(:to_f) || v
when /^\$(\w+)\.(\w+)$/
$1.constantize.arel_table[$2]
when Array
v.map { value(_1) }
when Hash
v.reject {|k, *| k.include?('.') }.
transform_values { value(_1) }.
merge(parse(v)).
tap {|h| h.merge!(h.delete('')) if h.key?('') }
v.reject {|k, *| k.include?('.') }
.transform_values { value(_1) }
.merge(parse(v))
.tap {|h| h.merge!(h.delete('')) if h.key?('') }
else
v
end
Expand Down
5 changes: 3 additions & 2 deletions lib/cafe_car/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def parse_time(value)

def parse_value(key, value)
case column(key)&.type
when :datetime
parse_time(value) || value
when :datetime then parse_time(value) || value
when :integer then value.to_i
when :float then value.to_f
else value
end
end
Expand Down

0 comments on commit 6b9ef9f

Please sign in to comment.