Top Level Namespace

Constant Summary collapse

SPACES =
"18"

Instance Method Summary collapse

Instance Method Details

#aObject

Take in args and hit API



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/npa_lookup.rb', line 54

ARGV.each do|a|
    uri = URI.parse("http://digits.cloudvox.com/#{parse_args(a)}.json")
    response = Net::HTTP.get_response(uri)
  begin
    jsonObject = JSON.parse(response.body)
  rescue JSON::ParserError => msg
    puts "Failed: #{msg.message} | #{a}.json"
    exit!
  end

  ## Simplify JSON structure 

    data = jsonObject['allocation']
    
    ## Start table (terminal-table)
    t = table ['Data', 'Value']
    t << [red("NPA","18"),yellow("#{data['npa']}",SPACES)]

    ## If nxx is not there don't include it in table
    if data['nxx']!=nil; t << [red("Nxx","18"),yellow("#{data['nxx']}",SPACES)];end

    ## If ratecenter_formatted is not there don't include it in table
    if data['ratecenter_formatted'] !=nil&&data['ratecenter_formatted']!=""; t << [red("City","18"),yellow("#{data['ratecenter_formatted']}",SPACES)]; end

    t << [red("State","18"),yellow("#{data['region']}",SPACES)]
    t << [red("Status","18"),yellow("#{data['status'].capitalize}",SPACES)]

    ## If carrier_name is not there don't include it in table
    if data['carrier_name'] !=nil; t << [red("Carrier","18"),yellow("#{data['carrier_name']}",SPACES)]; end

    puts t 
    puts "\n"
end

#blue(text, how_many_spaces) ⇒ Object



27
# File 'lib/npa_lookup.rb', line 27

def blue(text,how_many_spaces); colorize(text, 34,how_many_spaces); end

#colorize(text, color_code, how_many_spaces) ⇒ Object

colorize tables



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

def colorize(text, color_code,how_many_spaces)
  "\e[#{color_code}m#{text}\e[#{how_many_spaces}C\033[0m\033[0m"
end

#cyan(text, how_many_spaces) ⇒ Object



28
# File 'lib/npa_lookup.rb', line 28

def cyan(text,how_many_spaces); colorize(text, 36,how_many_spaces); end

#green(text, how_many_spaces) ⇒ Object



25
# File 'lib/npa_lookup.rb', line 25

def green(text,how_many_spaces); colorize(text, 32,how_many_spaces); end

#parse_args(i) ⇒ Object

format arguments for API call



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/npa_lookup.rb', line 32

def parse_args(i)
    begin 
      case safeParse(i).length
        when 3  
          return i
        when 6
          i=i.dup
          i.insert(3, '/')
        when 10
          return i
        else
          puts "Error {NumberError}"
          exit!
      end
  rescue Exception
    puts "#{i} is invalid"
    exit!
  end
end

#red(text, how_many_spaces) ⇒ Object



24
# File 'lib/npa_lookup.rb', line 24

def red(text,how_many_spaces); colorize(text, 31,how_many_spaces); end

#safeParse(strToParse) ⇒ Object

Make sure we have numbers



11
12
13
14
15
16
17
# File 'lib/npa_lookup.rb', line 11

def safeParse(strToParse)
  if strToParse =~ /\A\d+\Z/
    return strToParse.to_s
  else
    raise Exception
  end
end

#white(test, how_many_spaces) ⇒ Object



29
# File 'lib/npa_lookup.rb', line 29

def white(test,how_many_spaces);colorize(test,37,how_many_spaces);end

#yellow(text, how_many_spaces) ⇒ Object



26
# File 'lib/npa_lookup.rb', line 26

def yellow(text,how_many_spaces); colorize(text, 33,how_many_spaces); end