Class: Io::Flow::V0::Models::QueryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Overview

The query builder model is used to build a query using structured filters. The end result is a single ‘q’ string - e.g. ‘category:jewelry and brand:Flow’

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ QueryBuilder

Returns a new instance of QueryBuilder.



56469
56470
56471
56472
56473
56474
56475
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56469

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:q, :filters, :available], 'QueryBuilder')
  @q = HttpClient::Preconditions.assert_class('q', opts.delete(:q), String)
  @filters = HttpClient::Preconditions.assert_class('filters', opts.delete(:filters), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::QueryFilter) ? x : ::Io::Flow::V0::Models::QueryFilter.from_json(x)) }
  @available = HttpClient::Preconditions.assert_class('available', opts.delete(:available), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::AvailableFilter) ? x : ::Io::Flow::V0::Models::AvailableFilter.from_json(x)) }
end

Instance Attribute Details

#availableObject (readonly)

Returns the value of attribute available.



56467
56468
56469
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56467

def available
  @available
end

#filtersObject (readonly)

Returns the value of attribute filters.



56467
56468
56469
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56467

def filters
  @filters
end

#qObject (readonly)

Returns the value of attribute q.



56467
56468
56469
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56467

def q
  @q
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



56481
56482
56483
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56481

def copy(incoming={})
  QueryBuilder.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hashObject



56485
56486
56487
56488
56489
56490
56491
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56485

def to_hash
  {
    :q => q,
    :filters => filters.map { |o| o.to_hash },
    :available => available.map { |o| o.to_hash }
  }
end

#to_jsonObject



56477
56478
56479
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56477

def to_json
  JSON.dump(to_hash)
end