class SwedbankPay::SidebarTextBuilder

Builds a plain text representation of a Sidebar, suitable for a terminal.

Public Class Methods

new(page) click to toggle source
# File lib/sidebar_text_builder.rb, line 8
def initialize(page)
  raise ArgumentError, 'Page must be a SidebarPage' unless page.is_a? SidebarPage

  @page = page
end

Public Instance Methods

to_s() click to toggle source
# File lib/sidebar_text_builder.rb, line 14
def to_s
  name = @page.name == '/' ? '/' : "/#{@page.name}"
  lead_title = @page.title.nil? ? '?' : @page.title.lead
  main_title = @page.title.nil? ? '?' : @page.title.main
  s = "#{indent} #{@page.coordinate}. #{name}: #{lead_title} – #{main_title}\n"

  if @page.children?
    @page.children.each do |child|
      s << child.to_s
    end
  end

  # Only strip extraneous whitespace at the root page
  @page.level.zero? ? s.strip : s
end

Private Instance Methods

indent() click to toggle source
# File lib/sidebar_text_builder.rb, line 32
def indent
  # Return a special character for the first root page
  return '┍╾' if (@page.number.nil? || @page.number.zero?) && @page.parent.nil?

  increment = @page.level > 1 ? @page.level + 1 : @page.level

  "┝╾#{'─' * increment}"
end
todo() click to toggle source
# File lib/sidebar_text_builder.rb, line 41
def todo
  # This 'todo' method exists to circumvent the following RuboCop error:
  # lib/sidebar_text_builder.rb:39:97: C: Style/AsciiComments: Use only ascii symbols in comments.
  "TODO: Add logic to find the very last page regardless of level and have indent it with '┕╾─'"
end