Class: Csquery::Expression
- Inherits:
-
Object
- Object
- Csquery::Expression
- Defined in:
- lib/csquery/expression.rb
Instance Method Summary collapse
-
#initialize(operator, *args, options: {}, **kwargs) ⇒ Expression
constructor
A new instance of Expression.
- #query ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(operator, *args, options: {}, **kwargs) ⇒ Expression
Returns a new instance of Expression.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/csquery/expression.rb', line 3 def initialize(operator, *args, options: {}, **kwargs) @operator = operator = @fields = [] args.each do |arg| if arg.is_a? FieldValue @fields << arg else @fields << FieldValue.new(value: arg) end end kwargs.sort_by {|k, _| k }.each do |k, v| @fields << FieldValue.new(name: k, value: v) end end |
Instance Method Details
#query ⇒ Object
21 22 23 |
# File 'lib/csquery/expression.rb', line 21 def query "(#{@operator}#{Structured::format_options(@options)} #{@fields.map(&:to_s).join(' ')})".gsub(/\s+/, ' ') end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/csquery/expression.rb', line 25 def to_s query end |