Class: FattureInCloud_Ruby_Sdk::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/fattureincloud_ruby_sdk/filter/filter.rb

Overview

The Filter class is used to build a filter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression = nil) ⇒ Filter

Initializes a new instance of the Filter class.

Parameters:

  • expression (Expression) (defaults to: nil)

    The expression.



10
11
12
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 10

def initialize(expression = nil)
  @expression = expression
end

Instance Attribute Details

#expressionObject

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.

Parameters:

  • other (Filter)

    The filter to compare.

Returns:

  • (Boolean)

    True if the filters are equal, false otherwise.



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.

Parameters:

  • field (String)

    The field to compare.

  • operator (Operator)

    The operator to use.

  • [Numeric][Boolean][nil] (String)

    value The value to compare.



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.

Parameters:



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.

Parameters:

  • filter (Filter)

    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_queryString

Builds the query from the filter.

Returns:

  • (String)

    The query.



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_queryString

Builds the url encoded query from the filter.

Returns:

  • (String)

    The url encoded query.



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.

Parameters:

  • field (String)

    The field to compare.

  • operator (Operator)

    The operator to use.

  • [Numeric][Boolean][nil] (String)

    value The value to compare.



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.

Parameters:



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.

Parameters:

  • filter (Filter)

    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_sString

Builds the query from the filter.

Returns:

  • (String)

    The query.



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.

Parameters:

  • field (String)

    The field to compare.

  • operator (Operator)

    The operator to use.

  • [Numeric][Boolean][nil] (String)

    value The value to compare.



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.

Parameters:



25
26
27
28
# File 'lib/fattureincloud_ruby_sdk/filter/filter.rb', line 25

def where_expression(expression)
  @expression = expression
  self
end