Class: Sidenav

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_path:, navigation:, product:, locale: nil, code_language: nil, namespace: nil) ⇒ Sidenav

rubocop:disable Metrics/ParameterLists



5
6
7
8
9
10
11
12
13
14
# File 'lib/nexmo_developer/app/presenters/sidenav.rb', line 5

def initialize(request_path:, navigation:, product:, locale: nil, code_language: nil, namespace: nil)
  @request_path  = request_path
  @navigation    = navigation
  @product       = product
  @locale        = locale
  @code_language = code_language
  @namespace     = namespace

  after_initialize!
end

Instance Attribute Details

#code_languageObject (readonly)

Returns the value of attribute code_language.



2
3
4
# File 'lib/nexmo_developer/app/presenters/sidenav.rb', line 2

def code_language
  @code_language
end

#localeObject (readonly)

Returns the value of attribute locale.



2
3
4
# File 'lib/nexmo_developer/app/presenters/sidenav.rb', line 2

def locale
  @locale
end

Returns the value of attribute navigation.



2
3
4
# File 'lib/nexmo_developer/app/presenters/sidenav.rb', line 2

def navigation
  @navigation
end

#productObject (readonly)

Returns the value of attribute product.



2
3
4
# File 'lib/nexmo_developer/app/presenters/sidenav.rb', line 2

def product
  @product
end

#request_pathObject (readonly)

Returns the value of attribute request_path.



2
3
4
# File 'lib/nexmo_developer/app/presenters/sidenav.rb', line 2

def request_path
  @request_path
end

Instance Method Details

#documentation?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/nexmo_developer/app/presenters/sidenav.rb', line 55

def documentation?
  namespace == 'documentation'
end

#namespaceObject



51
52
53
# File 'lib/nexmo_developer/app/presenters/sidenav.rb', line 51

def namespace
  @namespace.presence || 'documentation'
end

rubocop:enable Metrics/ParameterLists



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nexmo_developer/app/presenters/sidenav.rb', line 17

def nav_items
  @nav_items ||= items.map do |item|
    if @request_path && @request_path.split('/')[1].include?(item[:title])
      SidenavItem.new(folder: item, sidenav: self)
    end
  end.compact

  if @nav_items.blank?
    @nav_items = items.map do |item|
      if @product && @product.split('/')[1] && @product.split('/')[1].include?(item[:title])
        SidenavItem.new(folder: item, sidenav: self)
      end
    end.compact
  end

  if @nav_items.blank?
    @nav_items = items.map do |item|
      if @product && @product.split('/')[0] && @product.split('/')[0].include?(item[:title])
        SidenavItem.new(folder: item, sidenav: self)
      end
    end.compact
  end

  if @nav_items.blank?
    @nav_items = items.map do |item|
      if @product && @product.split('/')[1].nil? && @product.include?(item[:title])
        SidenavItem.new(folder: item, sidenav: self)
      end
    end.compact
  end

  @nav_items
end