Class: NT54::Parser::Visitors::WaitForAreaCodeCompletion

Inherits:
NT54::Parser::Visitor show all
Defined in:
lib/nt54/parser/visitors/wait_for_area_code_completion.rb

Instance Attribute Summary

Attributes inherited from NT54::Parser::Visitor

#number

Instance Method Summary collapse

Methods inherited from NT54::Parser::Visitor

#initialize, #to_sym

Constructor Details

This class inherits a constructor from NT54::Parser::Visitor

Instance Method Details

#accept(keypress) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/nt54/parser/visitors/wait_for_area_code_completion.rb', line 5

def accept(keypress)
  super
  # Some area codes overlap, (e.g., 387 and 3873), so we need to check
  # for a 4-digit area code even if we already have a valid 3-digit one.
  candidate = @number.area_code + keypress
  if Area.key? candidate
    NT54.log.debug "#{candidate} is a valid area code" if NT54.log
    @number.area_code = candidate
    :area_code_completed
  elsif Area.key? @number.area_code
    NT54.log.debug "#{@number.area_code} is a valid area code" if NT54.log
    if keypress == "1"
      @number.mobile = true
      :mobile_prefix_started
    else
      @number.local_prefix << keypress
      :area_code_completed
    end
  else
    NT54.log.warn("Continuing with invalid or unknown area code") if NT54.log
    @number.local_prefix << keypress
    :area_code_completed
  end
end