Class: Zenlish::Inflect::MatchesPattern

Inherits:
UnaryInputExpression show all
Defined in:
lib/zenlish/inflect/matches_pattern.rb

Instance Attribute Summary collapse

Attributes inherited from UnaryInputExpression

#argument

Instance Method Summary collapse

Constructor Details

#initialize(anArgument, aPattern) ⇒ MatchesPattern

Returns a new instance of MatchesPattern.



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

def initialize(anArgument, aPattern)
  super(anArgument)
  @pattern = aPattern
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



6
7
8
# File 'lib/zenlish/inflect/matches_pattern.rb', line 6

def pattern
  @pattern
end

Instance Method Details

#success?(headings, lexeme, actuals) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/zenlish/inflect/matches_pattern.rb', line 13

def success?(headings, lexeme, actuals)
  val = nil
  if actuals.empty?
    # require 'debug'
    hd = headings[argument.index]
    val = hd.evaluate_for(lexeme)
  else
    val = actuals[argument.index]
  end
  val =~ pattern
end