class Attentive::Match
Attributes
listener[R]
match_end[R]
match_start[R]
message[R]
phrase[R]
Public Class Methods
new(phrase, attributes={})
click to toggle source
# File lib/attentive/match.rb, line 5 def initialize(phrase, attributes={}) @phrase = phrase.to_s @match_data = attributes.fetch(:match_data, {}) @match_start = attributes.fetch(:match_start) @match_end = attributes.fetch(:match_end) @message = attributes.fetch(:message) @listener = attributes[:listener] end
Public Instance Methods
[](variable_name)
click to toggle source
# File lib/attentive/match.rb, line 18 def [](variable_name) @match_data.fetch variable_name.to_s rescue KeyError raise KeyError, "#{$!.message} in #{inspect}" end
inspect()
click to toggle source
# File lib/attentive/match.rb, line 37 def inspect "#<#{self.class.name} #{@match_data.inspect} #{phrase.inspect}>" end
matched?(variable_name)
click to toggle source
# File lib/attentive/match.rb, line 14 def matched?(variable_name) !@match_data[variable_name.to_s].nil? end
replace_with(tokens)
click to toggle source
# File lib/attentive/match.rb, line 32 def replace_with(tokens) message[match_start...match_end] = tokens match_start + tokens.length end
to_h()
click to toggle source
# File lib/attentive/match.rb, line 28 def to_h @match_data end
to_s()
click to toggle source
# File lib/attentive/match.rb, line 24 def to_s @phrase end