Class: LocaleSwitcherPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo_developer/app/presenters/locale_switcher_presenter.rb

Constant Summary collapse

LOCALES =
{
  'cn' => '简体中文',
  'en' => 'English',
  'ja' => '日本語',
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ LocaleSwitcherPresenter

Returns a new instance of LocaleSwitcherPresenter.



8
9
10
# File 'lib/nexmo_developer/app/presenters/locale_switcher_presenter.rb', line 8

def initialize(request)
  @request = request
end

Instance Method Details

#available_localesObject



26
27
28
29
30
31
# File 'lib/nexmo_developer/app/presenters/locale_switcher_presenter.rb', line 26

def available_locales
  @available_locales ||= begin
    root = "#{Rails.configuration.docs_base_path}/_documentation"
    Dir["#{root}/*"].map { |path| path.gsub("#{root}/", '') }
  end
end

#current_localeObject



16
17
18
# File 'lib/nexmo_developer/app/presenters/locale_switcher_presenter.rb', line 16

def current_locale
  LOCALES[I18n.locale.to_s]
end

#disabled?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/nexmo_developer/app/presenters/locale_switcher_presenter.rb', line 12

def disabled?
  @request.controller_class == ActionDispatch::Request::PASS_NOT_FOUND
end

#localesObject



20
21
22
23
24
# File 'lib/nexmo_developer/app/presenters/locale_switcher_presenter.rb', line 20

def locales
  @locales ||= available_locales.map do |l|
    OpenStruct.new(data: l, value: LOCALES[l])
  end
end

#multiple_locales?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/nexmo_developer/app/presenters/locale_switcher_presenter.rb', line 33

def multiple_locales?
  locales.length > 1
end