Class: FattureInCloud_Ruby_Sdk::Condition
- Inherits:
-
Expression
- Object
- Expression
- FattureInCloud_Ruby_Sdk::Condition
- Defined in:
- lib/fattureincloud_ruby_sdk/filter/condition.rb
Overview
The Condition class represents a single condition in a filter.
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#operator ⇒ Object
Returns the value of attribute operator.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Overrides the == operator.
-
#build_query ⇒ String
Builds the query from the condition.
-
#initialize(field, operator, value) ⇒ Condition
constructor
Initializes a new instance of the Condition class.
-
#to_s ⇒ String
Builds the query from the condition.
Constructor Details
#initialize(field, operator, value) ⇒ Condition
Initializes a new instance of the Condition class.
12 13 14 15 16 |
# File 'lib/fattureincloud_ruby_sdk/filter/condition.rb', line 12 def initialize(field, operator, value) @field = field @operator = operator @value = value end |
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
6 7 8 |
# File 'lib/fattureincloud_ruby_sdk/filter/condition.rb', line 6 def field @field end |
#operator ⇒ Object
Returns the value of attribute operator.
6 7 8 |
# File 'lib/fattureincloud_ruby_sdk/filter/condition.rb', line 6 def operator @operator end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/fattureincloud_ruby_sdk/filter/condition.rb', line 6 def value @value end |
Instance Method Details
#==(other) ⇒ Boolean
Overrides the == operator.
47 48 49 50 51 52 53 |
# File 'lib/fattureincloud_ruby_sdk/filter/condition.rb', line 47 def ==(other) if other.instance_of? Condition @field == other.field && @operator == other.operator && @value == other.value else false end end |
#build_query ⇒ String
Builds the query from the condition.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fattureincloud_ruby_sdk/filter/condition.rb', line 20 def build_query if @field.nil? || @field == '' raise 'cannot build a query with an empty condition' end if @operator.nil? || @operator == '' raise 'cannot build a query with an empty operator' end if @value.nil? || @value == 'null' "#{@field} #{@operator} null" elsif @value.instance_of? String "#{@field} #{@operator} '#{@value}'" else "#{@field} #{@operator} #{@value}" end end |
#to_s ⇒ String
Builds the query from the condition.
40 41 42 |
# File 'lib/fattureincloud_ruby_sdk/filter/condition.rb', line 40 def to_s build_query end |