class OnappMarket::API::Query::Comparator

A simple class to wrap a comparison with a field and a value

Attributes

comparator[R]

Comparator (as a stirng e.g. GT, LT, GTE, LTE, EQ, REGEXP)

field[R]

Field to compare against

value[R]

The comparision value

Public Class Methods

new(field, comparator, value) click to toggle source

Create a new comparator instance

# File lib/onapp_market/api/query/comparators.rb, line 32
def initialize(field, comparator, value)
  @comparator = comparator
  @value = value unless @comparator == 'REGEXP' && value.is_a?(Regexp)
  @value = value.inspect if @comparator == 'REGEXP' && value.is_a?(Regexp)
  @field = field
end

Public Instance Methods

flatten() { |field| ... } click to toggle source

Flatten a comparator - yields field , comparator, value

# File lib/onapp_market/api/query/comparators.rb, line 50
def flatten
  yield @field
  yield @comparator
  yield @value
end
to_hash() click to toggle source

Convert to hash

Returns

Hash

# File lib/onapp_market/api/query/comparators.rb, line 60
def to_hash
  {"type" => "Comparator", "comparator" => @comparator, "field" => @field, "value" => @value}
end
to_s() click to toggle source

Can be used when flattening an expression to view in human readable form. Assumes value has sensible #to_s

Returns

  • String - the comparison e.g. length GT 4

# File lib/onapp_market/api/query/comparators.rb, line 44
def to_s
  "#{@field} #{@comparator} #{@value}"
end