Class: Attentive::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/attentive/match.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(phrase, attributes = {}) ⇒ Match

Returns a new instance of Match.



5
6
7
8
9
10
# File 'lib/attentive/match.rb', line 5

def initialize(phrase, attributes={})
  @phrase = phrase.to_s
  @match_data = attributes.fetch(:match_data, {})
  @listener = attributes[:listener]
  @message = attributes[:message]
end

Instance Attribute Details

#listenerObject (readonly)

Returns the value of attribute listener.



3
4
5
# File 'lib/attentive/match.rb', line 3

def listener
  @listener
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/attentive/match.rb', line 3

def message
  @message
end

#phraseObject (readonly)

Returns the value of attribute phrase.



3
4
5
# File 'lib/attentive/match.rb', line 3

def phrase
  @phrase
end

Instance Method Details

#[](variable_name) ⇒ Object



16
17
18
# File 'lib/attentive/match.rb', line 16

def [](variable_name)
  @match_data.fetch variable_name.to_s
end

#matched?(variable_name) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/attentive/match.rb', line 12

def matched?(variable_name)
  @match_data.key? variable_name.to_s
end

#to_sObject



20
21
22
# File 'lib/attentive/match.rb', line 20

def to_s
  @phrase
end