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.



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

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

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



7
8
9
# File 'lib/zenlish/inflect/inflection_rule.rb', line 7

def conditions
  @conditions
end

#consequentObject (readonly)

Returns the value of attribute consequent.



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

def consequent
  @consequent
end

Instance Method Details

#apply(theHeadings, aLexeme, actuals) ⇒ Object



19
20
21
# File 'lib/zenlish/inflect/inflection_rule.rb', line 19

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

#force_apply(theHeadings, aLexeme) ⇒ Object



23
24
25
# File 'lib/zenlish/inflect/inflection_rule.rb', line 23

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

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

Returns:

  • (Boolean)


15
16
17
# File 'lib/zenlish/inflect/inflection_rule.rb', line 15

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