class Hanoi::Jane::Formatters::Console
Attributes
fancy[RW]
stacks[RW]
Public Class Methods
assemble(stacks)
click to toggle source
# File lib/hanoi/jane/formatters/console.rb, line 17 def Console.assemble stacks a = [] (Console.rotate stacks).each_with_index do |r, index| divided = (index + 1) == stacks.first.length ? true : false a.push Console.row r, widest: Console.biggest(stacks), divided: divided end a.push [:horiz_divider] * a[0].length a end
biggest(stacks)
click to toggle source
# File lib/hanoi/jane/formatters/console.rb, line 38 def Console.biggest stacks stacks.map { |s| s.compact.max }.compact.max end
disc(size, width)
click to toggle source
# File lib/hanoi/jane/formatters/console.rb, line 42 def Console.disc size, width return [:space] * Hanoi::Jane.scale(width) unless size content = Hanoi::Jane.scale size gap = (Hanoi::Jane.scale(width) - content) / 2 output = [:disc] * content gap.times do [:unshift, :push].each do |method| output.send(method, :space) end end output end
new() { |self| ... }
click to toggle source
# File lib/hanoi/jane/formatters/console.rb, line 7 def initialize @fancy = false yield self if block_given? end
populate(stacks, fancy = false)
click to toggle source
# File lib/hanoi/jane/formatters/console.rb, line 29 def Console.populate stacks, fancy = false charset = fancy ? 'fancy' : 'regular' (Console.assemble stacks).map do |r| r.map do |c| Config.instance.config.chars[charset][c.to_s] end end end
rotate(stacks)
click to toggle source
# File lib/hanoi/jane/formatters/console.rb, line 69 def Console.rotate stacks stacks.map { |s| s.clone }.transpose.reverse end
row(starter, widest:, spacing: 1, divided: false)
click to toggle source
# File lib/hanoi/jane/formatters/console.rb, line 58 def Console.row starter, widest:, spacing: 1, divided: false filler = [:space] * spacing filler = [:vert_divider] if divided starter.map { |d| Console.disc d, widest }.flat_map { |d| [d, filler] }.unshift(filler).flatten end
Public Instance Methods
to_s()
click to toggle source
# File lib/hanoi/jane/formatters/console.rb, line 13 def to_s (Console.populate stacks, @fancy).map { |r| r.join '' }.join "\n" end