Class: Atomsphere::Query::SimpleExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/atomsphere/query/expression/simple_expression.rb

Overview

Constant Summary collapse

OPERATORS =

allowed values for #operator=

{
  equals:       1,
  like:         1,
  not_equals:   1,
  is_null:      0,
  is_not_null:  0,
  starts_with:  1,
  between:      2,
  greater_than: 1,
  less_than:    1,
  greater_than_or_equal: 1,
  less_than_or_equal: 1
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ SimpleExpression

Returns a new instance of SimpleExpression.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :property (String)

    the property/field to query

  • :operator (:equals, :like, :not_equals, :is_null, :is_not_null, :starts_with, :between, :greater_than, :less_than, :greater_than_or_equal, :less_than_or_equal)

    query operator

  • :argument (Array)

    array containing the number of arguments specified in the OPERATORS constant, as arguments to the query #operator



29
30
31
32
33
34
35
36
37
38
39
# 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

Instance Attribute Details

#argumentObject

Returns the value of attribute argument.



8
9
10
# File 'lib/atomsphere/query/expression/simple_expression.rb', line 8

def argument
  @argument
end

#operatorObject

Returns the value of attribute operator.



8
9
10
# File 'lib/atomsphere/query/expression/simple_expression.rb', line 8

def operator
  @operator
end

#propertyObject

Returns the value of attribute property.



8
9
10
# File 'lib/atomsphere/query/expression/simple_expression.rb', line 8

def property
  @property
end

Instance Method Details

#to_hashHash

returns a hash of the expression that will be sent to the boomi api with Atomsphere::Query#to_hash

Returns:

  • (Hash)

    hash representation of query that will be sent to the boomi api

See Also:



65
66
67
68
69
70
71
72
73
# 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!true, false

run all ‘validate_*!` private methods to ensure validity of expression parameters

Returns:

  • (true, false)


57
58
59
60
# 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