Class: Query::Decompiler
Class Method Summary collapse
Instance Method Summary collapse
- #decompile ⇒ Object
- #format_string(string) ⇒ Object
- #format_value(value) ⇒ Object
-
#initialize(parsed) ⇒ Decompiler
constructor
A new instance of Decompiler.
Constructor Details
#initialize(parsed) ⇒ Decompiler
Returns a new instance of Decompiler.
5 6 7 |
# File 'lib/query/decompiler.rb', line 5 def initialize(parsed) @parsed = parsed end |
Class Method Details
.decompile ⇒ Object
9 10 11 |
# File 'lib/query/decompiler.rb', line 9 def self.decompile(...) new(...).decompile end |
Instance Method Details
#decompile ⇒ Object
13 14 15 |
# File 'lib/query/decompiler.rb', line 13 def decompile parsed.map { |node| format_value(node) }.join(" ") end |
#format_string(string) ⇒ Object
17 18 |
# File 'lib/query/decompiler.rb', line 17 def format_string(string) end |
#format_value(value) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/query/decompiler.rb', line 20 def format_value(value) if value.is_a?(Hash) "#{value[:key]}#{value[:operator]}#{format_value(value[:value])}" elsif value.is_a?(String) Query.evaluate(value).many? ? value.inspect : value elsif value.is_a?(BigDecimal) value.to_s("F") elsif value.is_a?(Range) left = value.first right = value.last operator = value.exclude_end? ? "..." : ".." "#{format_value(left)}#{operator}#{format_value(right)}" else value.to_s end end |