Module: FFaker::NatoAlphabet

Extended by:
ModuleUtils, NatoAlphabet
Included in:
NatoAlphabet
Defined in:
lib/ffaker/nato_alphabet.rb

Constant Summary collapse

ALPHABET_CODES =
%w[ALPHA BRAVO CHARLIE DELTA ECHO FOXTROT GOLF HOTEL INDIA JULIETT KILO LIMA MIKE NOVEMBER OSCAR PAPA QUEBEC ROMEO SIERRA TANGO UNIFORM VICTOR WHISKEY XRAY YANKEE ZULU].freeze
NUMERIC_CODES =
%w[ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE ZERO].freeze
STOP_CODE =
'STOP'.freeze
CODES =
ALPHABET_CODES + NUMERIC_CODES + [STOP_CODE]

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore, unique

Methods included from RandomUtils

#fetch_sample, #rand, #shuffle

Instance Method Details

#alphabetic_codeObject


17
18
19
# File 'lib/ffaker/nato_alphabet.rb', line 17

def alphabetic_code
  fetch_sample(ALPHABET_CODES)
end

#callsignObject


25
26
27
# File 'lib/ffaker/nato_alphabet.rb', line 25

def callsign
  codify('?-?-#')
end

#codeObject


13
14
15
# File 'lib/ffaker/nato_alphabet.rb', line 13

def code
  fetch_sample(CODES)
end

#codify(masks) ⇒ Object


29
30
31
32
33
34
35
36
37
38
# File 'lib/ffaker/nato_alphabet.rb', line 29

def codify(masks)
  masks.scan(/./).map do |c|
    case c
    when '#' then fetch_sample(NUMERIC_CODES)
    when '?' then fetch_sample(ALPHABET_CODES)
    when '.' then STOP_CODE
    else c
    end
  end.join
end

#numeric_codeObject


21
22
23
# File 'lib/ffaker/nato_alphabet.rb', line 21

def numeric_code
  fetch_sample(NUMERIC_CODES)
end