Class: SwedbankPay::SidebarTextBuilder
- Inherits:
-
Object
- Object
- SwedbankPay::SidebarTextBuilder
- Defined in:
- lib/sidebar_text_builder.rb
Overview
Builds a plain text representation of a Sidebar, suitable for a terminal.
Instance Method Summary collapse
-
#initialize(page) ⇒ SidebarTextBuilder
constructor
A new instance of SidebarTextBuilder.
- #to_s ⇒ Object
Constructor Details
#initialize(page) ⇒ SidebarTextBuilder
Returns a new instance of SidebarTextBuilder.
8 9 10 11 12 |
# 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 |
Instance Method Details
#to_s ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 |