Sha256: 79aeec47ae95431dcf292049fcfbc3e5fd7add477a9dc0acc0c0a515d80d928a

Contents?: true

Size: 1.56 KB

Versions: 16

Compression:

Stored size: 1.56 KB

Contents

require_relative 'expression'

module FattureInCloud_Ruby_Sdk
  # The Condition class represents a single condition in a filter.
  class Condition < Expression
    attr_accessor :field, :operator, :value

    # Initializes a new instance of the Condition class.
    # @param [String] field The field to compare.
    # @param [Operator] operator The operator to use.
    # @param [String][Numeric][Boolean][nil] value The value to compare.
    def initialize(field, operator, value)
      @field = field
      @operator = operator
      @value = value
    end

    # Builds the query from the condition.
    # @return [String] The query.
    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

    # Builds the query from the condition.
    # @return [String] The query.
    def to_s
      build_query
    end

    # Overrides the == operator.
    # @param [Condition] other The condition to compare.
    # @return [Boolean] True if the conditions are equal, false otherwise.
    def ==(other)
      if other.instance_of? Condition
        @field == other.field && @operator == other.operator && @value == other.value
      else
        false
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
fattureincloud_ruby_sdk-2.1.1 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.1.0 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.20 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.19 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.18 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.17 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.16 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.15 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.14 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.13 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.12 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.11 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.10 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.9 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.8 lib/fattureincloud_ruby_sdk/filter/condition.rb
fattureincloud_ruby_sdk-2.0.7 lib/fattureincloud_ruby_sdk/filter/condition.rb