class NATOPhone::Encoder
Attributes
encode[RW]
Public Class Methods
new(args)
click to toggle source
Calls superclass method
NATOPhone::Base::new
# File lib/app.rb, line 37 def initialize(args) super(args) @dic = otan_alphabet_encode() @encode = convert(args) @translate = @encode.join(' ') @yell = @translate.upcase end
Public Instance Methods
to_a()
click to toggle source
# File lib/app.rb, line 58 def to_a @encode end
to_json()
click to toggle source
# File lib/app.rb, line 45 def to_json { 'args' => @args, 'encode' => @encode, 'translate' => @translate, 'yell' => @yell }.to_json end
to_s()
click to toggle source
# File lib/app.rb, line 54 def to_s @translate end
Private Instance Methods
check_input(input)
click to toggle source
# File lib/app.rb, line 71 def check_input(input) if input.is_a?(String) return input elsif input.is_a?(Array) return input.join(' ') else raise TypeError, "Error: Encoder accepts only Strings or Arrays." end end
convert(input)
click to toggle source
# File lib/app.rb, line 64 def convert(input) input = check_input(input) characters = sanitize(input).downcase.chars res = characters.map {|char| @dic[char]}.compact uniq_separator(res) end
uniq_separator(input)
click to toggle source
# File lib/app.rb, line 81 def uniq_separator(input) bucket = [] input.each do |c| bucket << c unless bucket.last == '-' && c == '-' end bucket end