Class: Quickbooks::Util::QueryBuilder
- Inherits:
-
Object
- Object
- Quickbooks::Util::QueryBuilder
- Defined in:
- lib/quickbooks/util/query_builder.rb
Constant Summary collapse
- VALUE_QUOTE =
"'"
Instance Method Summary collapse
- #clause(field, operator, value) ⇒ Object
-
#initialize ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
Constructor Details
#initialize ⇒ QueryBuilder
Returns a new instance of QueryBuilder.
9 10 |
# File 'lib/quickbooks/util/query_builder.rb', line 9 def initialize end |
Instance Method Details
#clause(field, operator, value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/quickbooks/util/query_builder.rb', line 12 def clause(field, operator, value) value = case value when DateTime, Time value.iso8601 when Date value.strftime('%Y-%m-%d') when Array value = value.map{|v| v.to_s.gsub("'", "\\\\'") } else # escape single quotes with an escaped backslash value = value.gsub("'", "\\\\'") end if operator.downcase == 'in' && value.is_a?(Array) value = value.map{|v| "#{VALUE_QUOTE}#{v}#{VALUE_QUOTE}"} "#{field} #{operator} (#{value.join(', ')})" else "#{field} #{operator} #{VALUE_QUOTE}#{value}#{VALUE_QUOTE}" end end |