Module: FFaker::Locale

Extended by:
Locale, ModuleUtils
Included in:
Locale
Defined in:
lib/ffaker/locale.rb

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, luhn_check, underscore, unique

Methods included from RandomUtils

#fetch_sample, #rand, #shuffle

Instance Method Details

#code(given_language = nil) ⇒ Object



8
9
10
11
12
13
# File 'lib/ffaker/locale.rb', line 8

def code(given_language = nil)
  code_index = LANGUAGE.index(given_language)
  return LANGUAGE_CODE[code_index] if given_language && code_index

  fetch_sample(LANGUAGE_CODE)
end

#language(given_code = nil) ⇒ Object



15
16
17
18
19
20
# File 'lib/ffaker/locale.rb', line 15

def language(given_code = nil)
  language_index = LANGUAGE_CODE.index(given_code&.upcase)
  return LANGUAGE[language_index] if given_code && language_index

  fetch_sample(LANGUAGE)
end