Class: Adhearsion::Call::Variables::Parser

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Parser

Returns a new instance of Parser.



465
466
467
468
# File 'lib/adhearsion/voip/call.rb', line 465

def initialize(io)
  @io = io
  @lines = []
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



464
465
466
# File 'lib/adhearsion/voip/call.rb', line 464

def io
  @io
end

#linesObject (readonly)

Returns the value of attribute lines.



464
465
466
# File 'lib/adhearsion/voip/call.rb', line 464

def lines
  @lines
end

#variablesObject (readonly)

Returns the value of attribute variables.



464
465
466
# File 'lib/adhearsion/voip/call.rb', line 464

def variables
  @variables
end

Class Method Details

.coerce_variables(variables) ⇒ Object



453
454
455
456
457
# File 'lib/adhearsion/voip/call.rb', line 453

def coerce_variables(variables)
  Coercions::COERCION_ORDER.inject(variables) do |tmp_variables, coercing_method_name|
    Coercions.send(coercing_method_name, tmp_variables)
  end
end

.parse(*args, &block) ⇒ Object



447
448
449
450
451
# File 'lib/adhearsion/voip/call.rb', line 447

def parse(*args, &block)
  new(*args, &block).tap do |parser|
    parser.parse
  end
end

.separate_line_into_key_value_pair(line) ⇒ Object



459
460
461
# File 'lib/adhearsion/voip/call.rb', line 459

def separate_line_into_key_value_pair(line)
  line.match(/^([^:]+):(?:\s?(.+)|$)/).captures
end

Instance Method Details

#parseObject



470
471
472
473
474
# File 'lib/adhearsion/voip/call.rb', line 470

def parse
  extract_variable_lines_from_io
  initialize_variables_as_hash_from_lines
  @variables = self.class.coerce_variables(variables)
end