Class: PuppetDBQuery::Term
- Inherits:
-
Object
- Object
- PuppetDBQuery::Term
- Defined in:
- lib/puppetdb_query/term.rb
Overview
represent a term containing an operator and arguments
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add(*arg) ⇒ Object
-
#initialize(operator) ⇒ Term
constructor
A new instance of Term.
- #to_s ⇒ Object
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
#args ⇒ Object (readonly)
Returns the value of attribute args.
5 6 7 |
# File 'lib/puppetdb_query/term.rb', line 5 def args @args end |
#operator ⇒ Object (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_s ⇒ Object
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 |