Class: Navigation

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

Constant Summary collapse

IGNORED_PATHS =
['..', '.', '.DS_Store'].freeze
LoadConfig.load_file('config/navigation.yml')
WEIGHT =
OVERRIDES =

Instance Method Summary collapse

Constructor Details

#initialize(folder) ⇒ Navigation

Returns a new instance of Navigation.



7
8
9
# File 'lib/nexmo_developer/app/presenters/navigation.rb', line 7

def initialize(folder)
  @folder = folder
end

Instance Method Details

#documentObject



41
42
43
# File 'lib/nexmo_developer/app/presenters/navigation.rb', line 41

def document
  @document ||= path_to_url.sub("#{product}/", '')
end

#optionsObject



11
12
13
14
15
# File 'lib/nexmo_developer/app/presenters/navigation.rb', line 11

def options
  @options ||= begin
    path_to_url.tr('/', '.').split('.').inject(OVERRIDES) { |h, k| h[k] || {} }
  end
end

#path_to_urlObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nexmo_developer/app/presenters/navigation.rb', line 17

def path_to_url
  @path_to_url ||= begin
    if @folder[:is_task?]
      path = @folder[:path].sub(@folder[:root], '')
      path.sub(%r{^/\w+/}, '').chomp('.yml')
    else
      path = @folder[:path].gsub("#{Rails.configuration.docs_base_path}/", '')
      path.sub(%r{^\w+/\w+/}, '').chomp('.md')
    end
  end
end

#productObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nexmo_developer/app/presenters/navigation.rb', line 29

def product
  @product ||= begin
    if @folder[:path].starts_with?('app/views')
      path_to_url.split('/').first
    else
      DocumentationConstraint.products_for_routes.find do |p|
        path_to_url.starts_with? p
      end
    end
  end
end