Class: GovukNavigationHelpers::StepNavContent

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_navigation_helpers/step_nav_content.rb

Constant Summary collapse

STEP_NAV_NAMES =
%w(
  learn-to-drive-a-car
).freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name: nil, path: nil) ⇒ StepNavContent

Returns a new instance of StepNavContent.



15
16
17
18
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 15

def initialize(file_name: nil, path: nil)
  @file_name = file_name
  @path = path
end

Class Method Details

.current_step_nav(path) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 7

def self.current_step_nav(path)
  STEP_NAV_NAMES.each do |step_nav_name|
    step_nav = new(file_name: step_nav_name, path: path)
    return step_nav if step_nav.current?
  end
  nil
end

Instance Method Details

#base_pathObject



24
25
26
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 24

def base_path
  parsed_file.dig(:base_path)
end

#current?Boolean

Returns:

  • (Boolean)


59
60
61
62
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 59

def current?
  primary_paths.include?(path) ||
    related_paths.include?(path)
end

#primary_pathsObject



36
37
38
39
40
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 36

def primary_paths
  primary_content.reject { |href|
    href.start_with?('http')
  }.select(&:present?)
end


46
47
48
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 46

def related_paths
  parsed_file.dig(:related_paths)
end

#set_current_stepObject



50
51
52
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 50

def set_current_step
  set_step_as_active_if_current_page
end

#show_step_nav?Boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 54

def show_step_nav?
  primary_paths.include?(path) ||
    related_paths.include?(path)
end


32
33
34
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 32

def skip_link
  "##{steps.first[:title].downcase.tr(' ', '-')}"
end

#step_navObject



28
29
30
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 28

def step_nav
  parsed_file.dig(:step_by_step_nav)
end

#stepsObject



42
43
44
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 42

def steps
  step_nav.dig(:steps)
end

#titleObject



20
21
22
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 20

def title
  parsed_file.dig(:title)
end