class Masheri::QueryBuilder::Where

Public Class Methods

new(hash = {}) click to toggle source
# File lib/masheri/query_builder.rb, line 97
def initialize(hash = {})
  @hash = hash
end

Public Instance Methods

add(hash) click to toggle source
# File lib/masheri/query_builder.rb, line 101
def add(hash)
  @hash.merge!(hash)
end
compute_relation() click to toggle source
# File lib/masheri/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() click to toggle source
# File lib/masheri/query_builder.rb, line 105
def to_s
  if @hash.blank?
    ""
  else
    "WHERE #{compute_relation}"
  end
end