Class: RubyAMI::AGIResultParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_ami/agi_result_parser.rb

Constant Summary

FORMAT =
/^(?<code>\d{3})( result=(?<result>-?\d*))? ?(?<data>\(?.*\)?)?$/.freeze
DATA_KV_FORMAT =
/(?<key>[\w\d]+)=(?<value>[\w\d]*)/.freeze
DATA_CLEANER =
/(^\()|(\)$)/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result_string) ⇒ AGIResultParser

Returns a new instance of AGIResultParser

Raises:

  • (ArgumentError)


11
12
13
14
15
# File 'lib/ruby_ami/agi_result_parser.rb', line 11

def initialize(result_string)
  @result_string = result_string.dup
  raise ArgumentError, "The result string (#{@result_string}) did not match the required format (#{FORMAT})." unless match
  parse
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code



5
6
7
# File 'lib/ruby_ami/agi_result_parser.rb', line 5

def code
  @code
end

#dataObject (readonly)

Returns the value of attribute data



5
6
7
# File 'lib/ruby_ami/agi_result_parser.rb', line 5

def data
  @data
end

#resultObject (readonly)

Returns the value of attribute result



5
6
7
# File 'lib/ruby_ami/agi_result_parser.rb', line 5

def result
  @result
end

Instance Method Details

#data_hashObject



17
18
19
20
# File 'lib/ruby_ami/agi_result_parser.rb', line 17

def data_hash
  return unless data_kv_match
  {data_kv_match[:key] => data_kv_match[:value]}
end