Class: Atomsphere::Query::GroupingExpression

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

Overview

Constant Summary collapse

OPERATORS =

allowed values for #operator=

:and, :or

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ GroupingExpression

Returns a new instance of GroupingExpression.

Parameters:

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

Options Hash (params):

  • :operator (:and, :or)

    query operator

  • :nested_expression (Array<Expression>)

    one or more Expressions



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/atomsphere/query/expression/grouping_expression.rb', line 16

def initialize(params={})
  case params
  when String
  when Symbol
    params = {operator: params}
  end

  params = {
    operator: :and,
    nested_expression: []
  }.merge(params)

  @operator = params[:operator]
  @nested_expression = params[:nested_expression]
end

Instance Attribute Details

#nested_expressionObject

Returns the value of attribute nested_expression.



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

def nested_expression
  @nested_expression
end

#operatorObject

Returns the value of attribute operator.



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

def operator
  @operator
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:



52
53
54
55
56
57
58
59
60
61
# File 'lib/atomsphere/query/expression/grouping_expression.rb', line 52

def to_hash
  {
    expression: {
      operator: operator.to_s,
      nestedExpression: nested_expression.
        map(&:to_hash).
        map{ |h| h[:expression] }
    }
  }
end

#validate!true, false

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

Returns:

  • (true, false)


42
43
44
45
46
47
# File 'lib/atomsphere/query/expression/grouping_expression.rb', line 42

def validate!
  private_methods.select{ |m| m =~ /^validate_[a-z0-9_]+\!$/ }.each{ |v| "#{v}"; send(v) }
  @nested_expression.each(&:validate!)

  true
end