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, underscore

Instance Method Details

#code(given_language = nil) ⇒ Object


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

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

#language(given_code = nil) ⇒ Object


17
18
19
20
21
22
23
24
# File 'lib/ffaker/locale.rb', line 17

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