Class: FattureInCloud_Ruby_Sdk::Filter
- Inherits:
-
Object
- Object
- FattureInCloud_Ruby_Sdk::Filter
- Defined in:
- lib/fattureincloud_ruby_sdk/filter/filter.rb
Overview
The Filter class is used to build a filter.
Instance Attribute Summary collapse
-
#expression ⇒ Object
Returns the value of attribute expression.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Overrides the == operator.
-
#and(field, operator, value) ⇒ Object
Adds an AND condition to the filter.
-
#and_expression(expression) ⇒ Object
Adds an AND expression to the filter.
-
#and_filter(filter) ⇒ Object
Adds an AND expression to the filter.
-
#build_query ⇒ String
Builds the query from the filter.
-
#build_url_encoded_query ⇒ String
Builds the url encoded query from the filter.
-
#initialize(expression = nil) ⇒ Filter
constructor
Initializes a new instance of the Filter class.
-
#or(field, operator, value) ⇒ Object
Adds an OR condition to the filter.
-
#or_expression(expression) ⇒ Object
Adds an OR expression to the filter.
-
#or_filter(filter) ⇒ Object
Adds an OR filter to the filter.
-
#to_s ⇒ String
Builds the query from the filter.
-
#where(field, operator, value) ⇒ Object
Initializes a new instance of the Filter class with a Condition.
-
#where_expression(expression) ⇒ Object
Initializes a new instance of the Filter class with an Expression.
Constructor Details
#initialize(expression = nil) ⇒ Filter
Initializes a new instance of the Filter class.
10 11 12 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 10 def initialize(expression = nil) @expression = expression end |
Instance Attribute Details
#expression ⇒ Object
Returns the value of attribute expression.
6 7 8 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 6 def expression @expression end |
Instance Method Details
#==(other) ⇒ Boolean
Overrides the == operator.
136 137 138 139 140 141 142 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 136 def ==(other) if other.instance_of? Filter @expression == other.expression else false end end |
#and(field, operator, value) ⇒ Object
Adds an AND condition to the filter.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 34 def and(field, operator, value) if @expression.nil? raise 'Cannot create a conjunction with an empty expression.' end left = @expression right = Condition.new(field, operator, value) @expression = Conjunction.new(left, right) self end |
#and_expression(expression) ⇒ Object
Adds an AND expression to the filter.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 47 def and_expression(expression) if @expression.nil? || expression.nil? raise 'Cannot create a conjunction with an empty expression.' end left = @expression right = expression @expression = Conjunction.new(left, right) self end |
#and_filter(filter) ⇒ Object
Adds an AND expression to the filter.
60 61 62 63 64 65 66 67 68 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 60 def and_filter(filter) if @expression.nil? || filter.nil? || filter.expression.nil? raise 'Cannot create a conjunction with an empty expression.' end left = @expression right = filter.expression @expression = Conjunction.new(left, right) end |
#build_query ⇒ String
Builds the query from the filter.
113 114 115 116 117 118 119 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 113 def build_query if @expression.nil? '' else @expression.build_query end end |
#build_url_encoded_query ⇒ String
Builds the url encoded query from the filter.
129 130 131 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 129 def build_url_encoded_query CGI.escape(build_query) end |
#or(field, operator, value) ⇒ Object
Adds an OR condition to the filter.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 74 def or(field, operator, value) if @expression.nil? raise 'Cannot create a disjunction with an empty expression.' end left = @expression right = Condition.new(field, operator, value) @expression = Disjunction.new(left, right) self end |
#or_expression(expression) ⇒ Object
Adds an OR expression to the filter.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 87 def or_expression(expression) if @expression.nil? || expression.nil? raise 'Cannot create a disjunction with an empty expression.' end left = @expression right = expression @expression = Disjunction.new(left, right) self end |
#or_filter(filter) ⇒ Object
Adds an OR filter to the filter.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 100 def or_filter(filter) if @expression.nil? || filter.nil? || filter.expression.nil? raise 'Cannot create a disjunction with an empty expression.' end left = @expression right = filter.expression @expression = Disjunction.new(left, right) self end |
#to_s ⇒ String
Builds the query from the filter.
123 124 125 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 123 def to_s build_query end |
#where(field, operator, value) ⇒ Object
Initializes a new instance of the Filter class with a Condition.
18 19 20 21 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 18 def where(field, operator, value) @expression = Condition.new(field, operator, value) self end |
#where_expression(expression) ⇒ Object
Initializes a new instance of the Filter class with an Expression.
25 26 27 28 |
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 25 def where_expression(expression) @expression = expression self end |