Module: FFaker::NatoAlphabet

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

Constant Summary collapse

STOP_CODE =
'STOP'
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


15
16
17
# File 'lib/ffaker/nato_alphabet.rb', line 15

def alphabetic_code
  fetch_sample(ALPHABET_CODES)
end

#callsignObject


23
24
25
# File 'lib/ffaker/nato_alphabet.rb', line 23

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

#codeObject


11
12
13
# File 'lib/ffaker/nato_alphabet.rb', line 11

def code
  fetch_sample(CODES)
end

#codify(masks) ⇒ Object


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

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


19
20
21
# File 'lib/ffaker/nato_alphabet.rb', line 19

def numeric_code
  fetch_sample(NUMERIC_CODES)
end