Class: Adhearsion::VoIP::CalculatedMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/adhearsion/voip/menu_state_machine/calculated_match.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CalculatedMatch

Returns a new instance of CalculatedMatch.



12
13
14
15
16
# File 'lib/adhearsion/voip/menu_state_machine/calculated_match.rb', line 12

def initialize(options={})
  @pattern, @query, @match_payload = options.values_at :pattern, :query, :match_payload
  @potential_matches = options[:potential_matches] ? Array(options[:potential_matches]) : []
  @exact_matches     = options[:exact_matches] ? Array(options[:exact_matches])     : []
end

Instance Attribute Details

#exact_matchesObject (readonly)

Returns the value of attribute exact_matches.



10
11
12
# File 'lib/adhearsion/voip/menu_state_machine/calculated_match.rb', line 10

def exact_matches
  @exact_matches
end

#match_payloadObject (readonly)

Returns the value of attribute match_payload.



10
11
12
# File 'lib/adhearsion/voip/menu_state_machine/calculated_match.rb', line 10

def match_payload
  @match_payload
end

#patternObject (readonly)

Returns the value of attribute pattern.



10
11
12
# File 'lib/adhearsion/voip/menu_state_machine/calculated_match.rb', line 10

def pattern
  @pattern
end

#potential_matchesObject (readonly)

Returns the value of attribute potential_matches.



10
11
12
# File 'lib/adhearsion/voip/menu_state_machine/calculated_match.rb', line 10

def potential_matches
  @potential_matches
end

#queryObject (readonly)

Returns the value of attribute query.



10
11
12
# File 'lib/adhearsion/voip/menu_state_machine/calculated_match.rb', line 10

def query
  @query
end

Class Method Details

.failed_match!(pattern, query, match_payload) ⇒ Object

Convenience method for instantiating failed matches



6
7
8
# File 'lib/adhearsion/voip/menu_state_machine/calculated_match.rb', line 6

def self.failed_match!(pattern, query, match_payload)
  new :pattern => pattern, :query => query, :match_payload => match_payload
end

Instance Method Details

#exact_match?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/adhearsion/voip/menu_state_machine/calculated_match.rb', line 18

def exact_match?
  exact_matches.any?
end

#failed_match?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/adhearsion/voip/menu_state_machine/calculated_match.rb', line 26

def failed_match?
  !potential_match? && !exact_match?
end

#potential_match?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/adhearsion/voip/menu_state_machine/calculated_match.rb', line 22

def potential_match?
  potential_matches.any?
end

#type_of_matchObject



30
31
32
33
34
35
36
# File 'lib/adhearsion/voip/menu_state_machine/calculated_match.rb', line 30

def type_of_match
  if exact_match?
    :exact
  elsif potential_match?
    :potential
  end
end