Sha256: 3448b9f5a36fad7880db93c729cee078c4d7f5ff0fc098662361c06b4a496539

Contents?: true

Size: 677 Bytes

Versions: 2

Compression:

Stored size: 677 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
    final_query = ''
    @queries.each do |_key, value|
      next unless value

      final_query << if value == @queries[@queries.keys.first]
                       value
                     else
                       @params[:search].present? ? " OR #{value}" : " AND #{value}"
                     end
    end

    final_query
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
seek_party-0.0.4 lib/seek_party/models/sp_query.rb
seek_party-0.0.3 lib/seek_party/models/sp_query.rb