Class: PuppetDBQuery::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/puppetdb_query/term.rb

Overview

represent a term containing an operator and arguments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator) ⇒ Term



7
8
9
10
# File 'lib/puppetdb_query/term.rb', line 7

def initialize(operator)
  @operator = operator
  @args = []
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/puppetdb_query/term.rb', line 5

def args
  @args
end

#operatorObject (readonly)

Returns the value of attribute operator.



4
5
6
# File 'lib/puppetdb_query/term.rb', line 4

def operator
  @operator
end

Instance Method Details

#==(other) ⇒ Object



17
18
19
# File 'lib/puppetdb_query/term.rb', line 17

def ==(other)
  other.class == self.class && other.operator == operator && other.args == args
end

#add(*arg) ⇒ Object



12
13
14
15
# File 'lib/puppetdb_query/term.rb', line 12

def add(*arg)
  @args += arg
  self
end

#to_sObject



21
22
23
24
25
26
27
28
29
# File 'lib/puppetdb_query/term.rb', line 21

def to_s
  if operator.prefix?
    "#{operator}(#{args.join(', ')})"
  elsif operator.infix?
    "(#{args.join(" #{operator} ")})"
  else
    raise "unkown representation for operator: #{operator}"
  end
end