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.



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

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

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



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

def pattern
  @pattern
end

Instance Method Details

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

Returns:

  • (Boolean)


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

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