3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/helpers/dbviewer/formatting_helper.rb', line 3
def format_cell_value(value)
return "NULL" if value.nil?
return value.to_s.truncate(100) unless value.is_a?(String)
case value
when /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
begin
Time.parse(value).strftime("%Y-%m-%d %H:%M:%S")
rescue
value.to_s.truncate(100)
end
when /\A\d{4}-\d{2}-\d{2}\z/
value
when /\A{.+}\z/, /\A\[.+\]\z/
begin
JSON.pretty_generate(JSON.parse(value)).truncate(100)
rescue
value.to_s.truncate(100)
end
else
value.to_s.truncate(100)
end
end
|