class NATOPhone::Decoder

Attributes

decode[RW]

Public Class Methods

new(args) click to toggle source
Calls superclass method NATOPhone::Base::new
# File lib/app.rb, line 95
def initialize(args)
  super(args)
  @dic = otan_alphabet_decode()
  @decode = convert(args)
  @translate = @decode.join()
  @yell = @translate.upcase
end

Public Instance Methods

to_a() click to toggle source
# File lib/app.rb, line 116
def to_a
  @decode
end
to_json() click to toggle source
# File lib/app.rb, line 103
def to_json
  {
    'args' => @args,
    'decode' => @decode,
    'translate' => @translate,
    'yell' => @yell
  }.to_json
end
to_s() click to toggle source
# File lib/app.rb, line 112
def to_s
  @translate
end

Private Instance Methods

convert(args) click to toggle source
# File lib/app.rb, line 122
def convert(args)
  words = if args.is_a?(String)
    convert_string(args)
  elsif args.is_a?(Array)
    convert_array(args)
  else
    raise TypeError, "Error: Decoder accepts only Strings or Arrays."
  end
  words.map {|word| @dic[word]}
end
convert_array(args) click to toggle source
# File lib/app.rb, line 137
def convert_array args
  words = []
  args.each do |string|
    string.split(' ').each do |word|
      words << word
    end
  end
  return words
end
convert_string(args) click to toggle source
# File lib/app.rb, line 133
def convert_string args
  args.split(' ').map {|word| word}
end