Class: Io::Flow::V0::Models::Query

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

Overview

The query model is used to present a query to a user, containing both the raw query as well as the filter representation of the query.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Query

Returns a new instance of Query.



56439
56440
56441
56442
56443
56444
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56439

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:q, :filters], 'Query')
  @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)) }
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



56437
56438
56439
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56437

def filters
  @filters
end

#qObject (readonly)

Returns the value of attribute q.



56437
56438
56439
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56437

def q
  @q
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



56450
56451
56452
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56450

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

#to_hashObject



56454
56455
56456
56457
56458
56459
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56454

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

#to_jsonObject



56446
56447
56448
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56446

def to_json
  JSON.dump(to_hash)
end