Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/passmakr.rb
Constant Summary collapse
- NATOALPHA =
["alfa", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliet", "kilo", "lima", "mike", "november", "oscar", "papa", "quebec", "romeo", "sierra", "tango", "uniform", "victor", "whiskey", "xray", "yankee", "zulu"]
- NATODIGITS =
["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
Instance Method Summary collapse
-
#to_nato ⇒ Object
Returns a NATO alphabet version of the string.
Instance Method Details
#to_nato ⇒ Object
Returns a NATO alphabet version of the string
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/passmakr.rb', line 315 def to_nato result = nil # for strings we call ourself recursively for each char to build up the eventual string if self.size > 1 result = self.split("").map {|c| c.to_nato }.join(" ") else ansi = self.bytes.first if ansi >= 65 && ansi <= 90 result = NATOALPHA[ansi-65].capitalize elsif ansi >= 97 && ansi <= 122 result = NATOALPHA[ansi-97] elsif ansi >= 48 && ansi <= 57 result = NATODIGITS[ansi-48] else result = self end end result end |