Class: Zenlish::Inflect::InflectionRule

Inherits:
Object
  • Object
show all
Defined in:
lib/zenlish/inflect/inflection_rule.rb

Overview

An inflection rule has two-parts:

  • a set of input conditions
  • a consequent part which tells how to inflect a lexeme

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theConditions, aConsequentExpr) ⇒ InflectionRule

Returns a new instance of InflectionRule.



12
13
14
15
# File 'lib/zenlish/inflect/inflection_rule.rb', line 12

def initialize(theConditions, aConsequentExpr)
  @conditions = theConditions
  @consequent = aConsequentExpr
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



9
10
11
# File 'lib/zenlish/inflect/inflection_rule.rb', line 9

def conditions
  @conditions
end

#consequentObject (readonly)

Returns the value of attribute consequent.



10
11
12
# File 'lib/zenlish/inflect/inflection_rule.rb', line 10

def consequent
  @consequent
end

Instance Method Details

#apply(theHeadings, aLexeme, actuals) ⇒ Object



21
22
23
# File 'lib/zenlish/inflect/inflection_rule.rb', line 21

def apply(theHeadings, aLexeme, actuals)
  consequent.generate(theHeadings, aLexeme, actuals)
end

#force_apply(theHeadings, aLexeme) ⇒ Object



25
26
27
# File 'lib/zenlish/inflect/inflection_rule.rb', line 25

def force_apply(theHeadings, aLexeme)
  consequent.generate(theHeadings, aLexeme)
end

#success?(theHeadings, aLexeme, actuals) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/zenlish/inflect/inflection_rule.rb', line 17

def success?(theHeadings, aLexeme, actuals)
  conditions.all? { |cond| cond.success?(theHeadings, aLexeme, actuals) }
end