Class: Mashery::QueryBuilder::Where

Inherits:
Object
  • Object
show all
Defined in:
lib/mashery/query_builder.rb

Instance Method Summary collapse

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_relationObject



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_sObject



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