class ConsoleView
Constants
- OUTPUT_WIDTH
Protected Instance Methods
line(char)
click to toggle source
# File lib/docfolio/views/view.rb, line 38 def line(char) ' ' * 27 + char * 18 + "\n" end
mins2hour(mins)
click to toggle source
# File lib/docfolio/views/view.rb, line 50 def mins2hour(mins) hours = (mins.to_r / 60).to_i mins -= hours * 60 hours == 1 ? h_str = 'hour' : h_str = 'hours' mins == 1 ? m_str = 'min' : m_str = 'mins' "#{hours}".rjust(30) + " #{h_str}".ljust(6) + "#{mins.to_i}".rjust(3) + " #{m_str}\n" end
print_array_section(title, body, list)
click to toggle source
# File lib/docfolio/views/view.rb, line 15 def print_array_section(title, body, list) return '' if body.empty? if list to_console("#{title}") + "\n\n" + to_console("⢠#{body.join("\n\n⢠")}\n\n", 2, 4) else to_console("#{title.gsub(/ $/, '')}") + to_console("#{body.join}\n\n").gsub(/ $/, '') end end
section_str(title, body = nil, list = false)
click to toggle source
# File lib/docfolio/views/view.rb, line 26 def section_str(title, body = nil, list = false) return '' if body.nil? case body when Array return '' if body.empty? print_array_section(title, body, list) when String return '' if body.strip == '' "#{title}\n\n#{body}" end end
sub_total_line()
click to toggle source
# File lib/docfolio/views/view.rb, line 42 def sub_total_line line('ā') end
to_console(str, first_line_margin = 0, margin = 0)
click to toggle source
# File lib/docfolio/views/view.rb, line 74 def to_console(str, first_line_margin = 0, margin = 0) return_str = '' str.each_line do |line| if line == "\n" return_str += "\n\n" next end return_str += ' ' * first_line_margin x_pos = first_line_margin words = line.split(' ') words.each do |word| x_pos, this_str = word2console(word, x_pos, margin) return_str += this_str + ' ' end end return_str end
total_line()
click to toggle source
# File lib/docfolio/views/view.rb, line 46 def total_line line('ā') end
word2console(word, x_pos, margin)
click to toggle source
prints the word to the console
# File lib/docfolio/views/view.rb, line 60 def word2console(word, x_pos, margin) str = '' length = 1 + rm_colour(word).length if x_pos + length >= OUTPUT_WIDTH str += "\n" + (' ' * margin) x_pos = margin + length else x_pos += length end str != '' ? debug = true : debug = false str += word [x_pos, str] end