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 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bars.rb', line 9 def print(={}) print_mode = .delete(:print_mode) { 'bars' } line_width = .delete(:line_width) { 20 } - 1 puts @timeframes.each do |timeframe, tasks| puts " #{timeframe.capitalize} ".center(30, "*") tasks.each do |task, done, goal| done_percent = (done.to_f/goal) if print_mode == 'percent' left_side = "#{task}:".ljust(line_width) right_side = "#{(done_percent * 100).floor}%".rjust(4) puts "--> #{left_side}#{right_side}" else puts "--> #{task}:" done_string = "+" * (done_percent * line_width) todo_string = "-" * (line_width - done_string.length) if done == 0 splitter = '-' elsif done == goal splitter = '+' else splitter = '|' end puts " |#{done_string}#{splitter}#{todo_string}|" end end puts end end |