class Rule

Attributes

map[RW]
rule[RW]

Public Class Methods

new(map, &block) click to toggle source
# File lib/Rule/rule.rb, line 8
def initialize(map, &block)
  self.rule = Proc.new(&block)
  self.map = map
end

Public Instance Methods

as_proposition() click to toggle source
# File lib/Rule/rule.rb, line 23
def as_proposition
  rule.to_source(strip_enclosure: true).gsub(/>|>=/, 'then')
      .gsub(/<|<=/, 'then !')
      .gsub(/==|equal\?/, 'only_if')
      .gsub(/nil\?/, '!= nil')
      .gsub(/\d+/) do |match|
    map.fetch(match)
  end
      .tr('.', ' ')[1..-2]
end
contradictory?(other_rule) click to toggle source
# File lib/Rule/rule.rb, line 17
def contradictory?(other_rule)
  analyzer = LogicAnalyzer.new(as_proposition, other_rule.as_proposition)
  analyzer.parse
  !analyzer.evaluate
end
satisfies?(object) click to toggle source
# File lib/Rule/rule.rb, line 13
def satisfies?(object)
  object.instance_eval(&rule)
end