Class: Bars
- Inherits:
-
Object
- Object
- Bars
- Defined in:
- lib/bars.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Bars
constructor
A new instance of Bars.
- #print(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Bars
Returns a new instance of Bars.
4 5 6 7 |
# File 'lib/bars.rb', line 4 def initialize(={}) file_path = .delete(:file_path) { '~/bars.yml' } @timeframes = YAML.load(File.open(File.(file_path))) end |
Instance Method Details
#print(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bars.rb', line 9 def print(={}) line_width = .delete(:line_width) { 25 } - 1 puts @timeframes.each do |timeframe, tasks| tasks.each do |task, done, goal| percent = (done.to_f/goal) count = (percent * line_width.to_f).round done_string = "█" * (count) todo_string = "┅" * (line_width - count) percent_string = sprintf("%.1f%", (percent * 100)).rjust(6) goal_string = "#{done}/#{goal}".rjust(7) puts "#{task.ljust(line_width - 7)}#{goal_string}" puts "#{done_string}#{todo_string}#{percent_string}" end puts end end |