class Zenlish::Inflect::InflectionTableBuilder

Attributes

conds[R]
headings[R]
rules[R]
table[R]

Name of decision table

Public Class Methods

new() click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 41
def initialize
  reset
end

Public Instance Methods

build(aTableName, &aBlock) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 45
def build(aTableName, &aBlock)
  reset
  @table = InflectionTable.new(aTableName)
  instance_exec(&aBlock) if block_given?
  @table
end
col(aColName) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 108
def col(aColName)
  col_index = headings.find_index { |hd| hd.label == aColName }
  err_msg = "Cannot find heading named '#{aColName}'."
  raise StandardError, err_msg if col_index.nil?

  formal = FormalArgument.new(col_index)
  InputAsIs.new(formal)
end
concat(arg1, arg2) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 132
def concat(arg1, arg2)
  Concatenation.new(arg1, arg2)
end
dont_care() click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 97
def dont_care
  item = UnconditionallyTrue.new
  conds << item

  item
end
equals(aValue) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 73
def equals(aValue)
  arg = FormalArgument.new(conds.size)
  equality_cond = EqualsLiteral.new(arg, aValue)
  conds << equality_cond

  equality_cond
end
feature_heading(aFeatureName) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 52
def feature_heading(aFeatureName)
  hd = FeatureHeading.new(aFeatureName)
  headings << hd
  table&.add_heading(hd)
end
func(aFuncName) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 124
def func(aFuncName)
  FunctionCall.new(aFuncName)
end
in?(*theMembers) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 89
def in?(*theMembers)
  arg = FormalArgument.new(conds.size)
  membership_cond = Membership.new(arg, theMembers)
  conds << membership_cond

  membership_cond
end
literal(aLiteral) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 104
def literal(aLiteral)
  LiteralAsIs.new(aLiteral)
end
matches(aPattern) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 117
def matches(aPattern)
  arg = FormalArgument.new(conds.size)
  match_cond = MatchesPattern.new(arg, aPattern)
  conds << match_cond
  match_cond
end
method_heading(aMethodName) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 58
def method_heading(aMethodName)
  hd = MethodHeading.new(aMethodName)
  headings << hd
  table&.add_heading(hd)
end
not_equal(aValue) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 81
def not_equal(aValue)
  arg = FormalArgument.new(conds.size)
  inequality_cond = NotEqualsLiteral.new(arg, aValue)
  conds << inequality_cond

  inequality_cond
end
rule(conditions, consequent) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 64
def rule(conditions, consequent)
  @conds = []
  rl = InflectionRule.new(conditions.dup, consequent)
  rules << rl
  table&.add_rule(rl)

  rl
end
sub(original, pattern, replacement) click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 128
def sub(original, pattern, replacement)
  Substitution.new(original, pattern, replacement)
end

Private Instance Methods

reset() click to toggle source
# File lib/zenlish/inflect/inflection_table_builder.rb, line 138
def reset
  @table = nil
  @headings = []
  @conds = []
  @rules = []
end