Class: Mashery::QueryBuilder::Where
- Inherits:
-
Object
- Object
- Mashery::QueryBuilder::Where
- Defined in:
- lib/mashery/query_builder.rb
Instance Method Summary collapse
- #add(hash) ⇒ Object
- #compute_relation ⇒ Object
-
#initialize(hash = {}) ⇒ Where
constructor
A new instance of Where.
- #to_s ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Where
Returns a new instance of Where.
97 98 99 |
# File 'lib/mashery/query_builder.rb', line 97 def initialize(hash = {}) @hash = hash end |
Instance Method Details
#add(hash) ⇒ Object
101 102 103 |
# File 'lib/mashery/query_builder.rb', line 101 def add(hash) @hash.merge!(hash) end |
#compute_relation ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/mashery/query_builder.rb', line 113 def compute_relation @hash.map do |key, value| if value.is_a? String "#{key} = '#{value}'" else "#{key} = #{value}" end end.join(" AND ") end |
#to_s ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/mashery/query_builder.rb', line 105 def to_s if @hash.blank? "" else "WHERE #{compute_relation}" end end |