Sha256: 4a61920a7bbac248d74e84bedce25006337ac2df508ac4d1d294e8ec1667d7d9

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module FluentConditions
  class ConditionBuilder
    def initialize(object, type)
      @object = object
      @type = type
      @previous, @current, @big_or = true, true, false
    end

    def or
      @or_used = true
      self
    end

    def OR
      update_big_or_result
      @big_or_used = true
      self
    end

    def and
      self
    end

    private

    def update_and_continue(field_value)
      update_current_result(field_value)
      self
    end

    def update_and_finish(field_value)
      update_current_result(field_value)
      update_big_or_result if @big_or_used
      end_result
    end

    def update_current_result(field_value)
      if @or_used
        @current = @current || field_value
        @or_used = false
      else
        @previous, @current = @previous && @current, field_value
      end
    end

    def update_big_or_result
      @big_or = @big_or || current_result
      @previous, @current = true, true
    end

    def current_result
      @previous && @current 
    end

    def end_result
      @type == :positive ? sub_result : !sub_result
    end

    def sub_result
      @big_or_used ? @big_or : current_result
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent_conditions-0.0.3 lib/fluent_conditions/condition_builder.rb