lib/hbtrack/habit_printer.rb in hbtrack-0.0.5 vs lib/hbtrack/habit_printer.rb in hbtrack-0.0.6

- old
+ new

@@ -1,45 +1,53 @@ # frozen_string_literal: true +require 'hbtrack/util' + module Hbtrack - # This class contains the methods that + # This class contains the methods that # are used to format the progress of a Habit # into string class HabitPrinter + attr_accessor :formatter - def initialize(stat_formatter) - @stat_formatter = stat_formatter + def initialize(formatter = CompleteSF.new) + @formatter = formatter end def calculate_space_needed_for(habit, key) habit.longest_month.length - Util.get_month_from(key).length end def print_latest_progress(habit, no_of_space = 0) habit.name.to_s + ' ' * no_of_space + ' : ' + - print_progress( - habit.latest_progress, - habit.latest_stat - ) + print_progress( + habit.latest_progress, + habit.latest_stat + ) end def print_all_progress(habit) - habit.progress.map do |key, value| + habit.progress.map do |key, value| space = calculate_space_needed_for(habit, key) Util.convert_key_to_date(key, space) + - print_progress( - value, - habit.stat_for_progress(key) - ) + print_progress( + value, + habit.stat_for_progress(key) + ) end.join("\n") end def print_progress(progress, stat) output = progress.split('').map do |x| - x == '0' ? CLI.red('*') : CLI.green('*') + if x == '0' + Util.red('*') + elsif x == '1' + Util.green('*') + else + ' ' + end end.join('') output + ' ' * (32 - progress.size) + - @stat_formatter.format(stat) + @formatter.format(stat) end end end -