Class: Bars

Inherits:
Object
  • Object
show all
Defined in:
lib/bars.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Bars

Returns a new instance of Bars.



4
5
6
7
# File 'lib/bars.rb', line 4

def initialize(options={})
  file_path = options.delete(:file_path) { '~/bars.yml' }
  @timeframes = YAML.load(File.open(File.expand_path(file_path)))
end

Instance Method Details



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(options={})
  line_width = options.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