Class: FattureInCloud_Ruby_Sdk::Condition

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

Overview

The Condition class represents a single condition in a filter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, operator, value) ⇒ Condition

Initializes a new instance of the Condition class.

Parameters:

  • field (String)

    The field to compare.

  • operator (Operator)

    The operator to use.

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

    value The value to compare.



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

#fieldObject

Returns the value of attribute field.



6
7
8
# File 'lib/fattureincloud_ruby_sdk/filter/condition.rb', line 6

def field
  @field
end

#operatorObject

Returns the value of attribute operator.



6
7
8
# File 'lib/fattureincloud_ruby_sdk/filter/condition.rb', line 6

def operator
  @operator
end

#valueObject

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.

Parameters:

  • other (Condition)

    The condition to compare.

Returns:

  • (Boolean)

    True if the conditions are equal, false otherwise.



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_queryString

Builds the query from the condition.

Returns:

  • (String)

    The query.



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_sString

Builds the query from the condition.

Returns:

  • (String)

    The query.



40
41
42
# File 'lib/fattureincloud_ruby_sdk/filter/condition.rb', line 40

def to_s
  build_query
end