module Epi::Triggers::Concerns::Comparison

Public Instance Methods

compare(subject) click to toggle source
# File lib/epi/triggers/concerns/comparison.rb, line 6
def compare(subject)
  tester.call subject, object
end

Private Instance Methods

choose_tester() click to toggle source
# File lib/epi/triggers/concerns/comparison.rb, line 24
def choose_tester
  case op
    when :gt then -> a, b { a > b }
    when :lt then -> a, b { a < b }
    when :gte then -> a, b { a >= b }
    when :lte then -> a, b { a <= b }
    when :eq then -> a, b { a == b }
    when :not_eq then -> a, b { a != b}
    when :match then -> a, b { a =~ b }
    when :not_match then -> a, b { a !~ b }
    when :like then -> a, b { a === b }
    when :not_like then -> a, b { !(a === b) }
    else raise Exceptions::Fatal, "Unknown operation #{op}"
  end
end
object() click to toggle source
# File lib/epi/triggers/concerns/comparison.rb, line 20
def object
  @object ||= args[1]
end
op() click to toggle source
# File lib/epi/triggers/concerns/comparison.rb, line 16
def op
  @op ||= args[0]
end
tester() click to toggle source
# File lib/epi/triggers/concerns/comparison.rb, line 12
def tester
  @tester ||= choose_tester
end