Class: Atomsphere::Query::SimpleExpression

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

Constant Summary collapse

OPERATORS =
{
  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.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/atomsphere/query/simple_expression.rb', line 22

def initialize(params={})
  params = {
    operator: :equals,
    property: nil,
    argument: []
  }.merge(params)

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

Instance Attribute Details

#argumentObject

Returns the value of attribute argument.



6
7
8
# File 'lib/atomsphere/query/simple_expression.rb', line 6

def argument
  @argument
end

#operatorObject

Returns the value of attribute operator.



6
7
8
# File 'lib/atomsphere/query/simple_expression.rb', line 6

def operator
  @operator
end

#propertyObject

Returns the value of attribute property.



6
7
8
# File 'lib/atomsphere/query/simple_expression.rb', line 6

def property
  @property
end

Instance Method Details

#to_hashObject



39
40
41
42
43
44
45
46
47
# File 'lib/atomsphere/query/simple_expression.rb', line 39

def to_hash
  {
    expression: {
      operator: operator.upcase,
      property: property,
      argument: [*argument]
    }
  }
end

#to_jsonObject



49
50
51
# File 'lib/atomsphere/query/simple_expression.rb', line 49

def to_json
  to_hash.to_json
end

#validate!Object



34
35
36
37
# File 'lib/atomsphere/query/simple_expression.rb', line 34

def validate!
  private_methods.select{ |m| m =~ /^validate_[a-z0-9_]+\!$/ }.each{ |v| send(v) }
  true
end