lib/fat_table/table.rb in fat_table-0.6.2 vs lib/fat_table/table.rb in fat_table-0.6.3
- old
+ new
@@ -950,23 +950,28 @@
new_cols.each_pair do |key, expr|
key = key.as_sym
vars = old_row.merge(new_row)
case expr
when Symbol
- msg = "Column '#{expr}' in select does not exist"
+ msg = "select column '#{expr}' does not exist"
raise UserError, msg unless vars.key?(expr)
new_row[key] = vars[expr]
when String
- new_row[key] = ev.evaluate(expr, locals: vars)
+ if expr.match?(/\A\s*:/)
+ # Leading colon signal a literal string
+ new_row[key] = expr.sub(/\A\s*:/, '')
+ else
+ # Otherwise, evaluate the string.
+ new_row[key] = ev.evaluate(expr, locals: vars)
+ end
+ when Numeric, DateTime, Date, TrueClass, FalseClass
+ new_row[key] = expr
else
- msg = "Hash parameter '#{key}' to select must be a symbol or string"
+ msg = "select can't set column at '#{key}' to '#{expr}' of class #{expr.class}"
raise UserError, msg
end
end
- # Set the group number and run the hook with the local variables set to
- # the row after the new row is evaluated.
- # vars = new_row.merge(__group: grp)
ev.eval_after_hook(locals: new_row)
result << new_row
end
result.explicit_boundaries = explicit_boundaries
result.normalize_boundaries