Sha256: b37a6165e2ec71ee9df7edfdf9e30e31e15fdf2831dc2876bfd3cdee40338675

Contents?: true

Size: 566 Bytes

Versions: 1

Compression:

Stored size: 566 Bytes

Contents

class SPQuery
  attr_accessor :queries, :params

  def initialize(queries: {}, params: nil)
    @queries = queries
    @params = params
  end

  def add_attribute_query(attribute, query)
    @queries[attribute] << query
  end

  def set_attribute_query(attribute, query)
    @queries[attribute] = query
  end

  def build_final_query
    @queries.map { |key, value|
      if key == @queries.keys.first
        value
      else
        or_and(value)
      end }.sum
  end

  def or_and(value)
    @params[:search].present? ? " OR #{value}" : " AND #{value}"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seek_party-0.0.5 lib/seek_party/models/sp_query.rb