class Atomsphere::Query::SimpleExpression

@see help.boomi.com/atomsphere/GUID-4CAE5616-76EB-4C58-B2E3-4173B65EA7EC.html

Constants

OPERATORS

allowed values for {#operator=}

Attributes

argument[RW]
operator[RW]
property[RW]

Public Class Methods

new(params={}) click to toggle source

@param [Hash] params @option params [String] :property the property/field to query @option params [:equals,:like,:not_equals,:is_null,:is_not_null,:starts_with,:between,:greater_than,:less_than,:greater_than_or_equal,:less_than_or_equal] :operator query operator @option params [Array] :argument array containing the number of arguments specified in the {OPERATORS} constant, as arguments to the query {#operator}

# File lib/atomsphere/query/expression/simple_expression.rb, line 29
def initialize(params={})
  params = {
    operator: :equals,
    property: nil,
    argument: []
  }.merge(params)

  %w(operator property argument).each do |v|
    send :"#{v}=", params[v.to_sym]
  end
end

Public Instance Methods

argument=(arg) click to toggle source
# File lib/atomsphere/query/expression/simple_expression.rb, line 51
def argument= arg
  instance_variable_set :@argument, arg.map(&:to_s)
end
operator=(arg) click to toggle source
# File lib/atomsphere/query/expression/simple_expression.rb, line 75
def operator= arg
  unless OPERATORS.keys.include? arg.to_sym
    raise ArgumentError, "operator must be one of: #{OPERATORS.keys.join(', ')}"
  end

  instance_variable_set :@operator, arg.to_sym
end
property=(arg) click to toggle source
# File lib/atomsphere/query/expression/simple_expression.rb, line 41
def property= arg
  instance_variable_set :@property,
    case arg
    when String
      arg
    when Symbol
      arg.to_s.lower_camelcase
    end
end
to_hash() click to toggle source

returns a hash of the expression that will be sent to the boomi api with {Query#to_hash} @see to_json @return [Hash] hash representation of query that will be sent to the boomi api

# File lib/atomsphere/query/expression/simple_expression.rb, line 65
def to_hash
  {
    expression: {
      operator: operator.to_s.upcase,
      property: property.to_s,
      argument: [*argument].map(&:to_s)
    }
  }
end
validate!() click to toggle source

run all `validate_*!` private methods to ensure validity of expression parameters @return [true, false]

# File lib/atomsphere/query/expression/simple_expression.rb, line 57
def validate!
  private_methods.select{ |m| m =~ /^validate_[a-z0-9_]+\!$/ }.each{ |v| send(v) }
  true
end

Private Instance Methods

validate_argument!() click to toggle source
# File lib/atomsphere/query/expression/simple_expression.rb, line 94
def validate_argument!
  unless [*argument].size.eql?(OPERATORS[operator])
    raise ArgumentError, "'#{operator}' expects #{OPERATORS[operator]} argument(s)"
  end
end
validate_operator!() click to toggle source
# File lib/atomsphere/query/expression/simple_expression.rb, line 84
def validate_operator!
  unless OPERATORS.include? operator
    raise ArgumentError, "operator must be one of #{OPERATORS.join(', ')}"
  end
end
validate_property!() click to toggle source
# File lib/atomsphere/query/expression/simple_expression.rb, line 90
def validate_property!
  raise ArgumentError, "property must be specified" unless @property
end