class Syllogism::TermDistributor

Attributes

atoms[R]
current[RW]
position[RW]
terms[R]

Public Class Methods

new(statement) click to toggle source
# File lib/syllogism/term_distributor.rb, line 3
def initialize(statement)
  @atoms = statement.atoms
  @current = nil
  @position = 0
  @terms = statement.terms
end

Public Instance Methods

call() click to toggle source
# File lib/syllogism/term_distributor.rb, line 10
def call
  atoms.each_with_index do |atom, index|
    self.current, self.position = atom, index
    if term?
      atom.distributed = should_distribute?
    end
  end
end

Private Instance Methods

anywhere_after_no?() click to toggle source
# File lib/syllogism/term_distributor.rb, line 24
def anywhere_after_no?
  preceeding_types.include?(No)
end
immediate_predecessor() click to toggle source
# File lib/syllogism/term_distributor.rb, line 36
def immediate_predecessor
  preceeding_types.last
end
immediately_after_all?() click to toggle source
# File lib/syllogism/term_distributor.rb, line 28
def immediately_after_all?
  immediate_predecessor == All
end
immediately_after_not?() click to toggle source
# File lib/syllogism/term_distributor.rb, line 32
def immediately_after_not?
  immediate_predecessor == Negation
end
preceeding_types() click to toggle source
# File lib/syllogism/term_distributor.rb, line 40
def preceeding_types
  atoms.take(position).map(&:class)
end
should_distribute?() click to toggle source
# File lib/syllogism/term_distributor.rb, line 44
def should_distribute?
  immediately_after_all? || immediately_after_not? || anywhere_after_no?
end
term?() click to toggle source
# File lib/syllogism/term_distributor.rb, line 48
def term?
  terms.include?(current)
end