bars 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/bars +14 -1
  2. data/lib/bars.rb +15 -11
  3. metadata +3 -3
data/bin/bars CHANGED
@@ -4,5 +4,18 @@
4
4
 
5
5
  require 'bars'
6
6
 
7
- bars = Bars.new(ARGV)
7
+ options = {}
8
+ ARGV.each_with_index do |arg, index|
9
+ if arg == '-p'
10
+ options[:print_mode] = :percentage
11
+ elsif arg == '-n'
12
+ if ARGV[index+1]
13
+ options[:bar_size] = ARGV[index+1]
14
+ else
15
+ raise "you need to enter a number"
16
+ end
17
+ end
18
+ end
19
+
20
+ bars = Bars.new(options)
8
21
  bars.print
data/lib/bars.rb CHANGED
@@ -1,13 +1,9 @@
1
1
  require 'yaml'
2
2
 
3
3
  class Bars
4
- def initialize(args=[])
5
- if !args.empty? && args.first == '-p'
6
- @print_mode = :percentage
7
- else
8
- @print_mode = :bars
9
- end
10
-
4
+ def initialize(options={})
5
+ @print_mode = options.delete(:print_mode) { :bars }
6
+ @bar_size = options.delete(:bar_size) { 20 }
11
7
  @timeframes = YAML.load(File.open(File.expand_path('~/bars.yml')))
12
8
  end
13
9
 
@@ -16,13 +12,21 @@ class Bars
16
12
  @timeframes.each do |timeframe, tasks|
17
13
  puts " #{timeframe.capitalize} ".center(30, "*")
18
14
  tasks.each do |task, done, goal|
15
+ done_percent = (done.to_f/goal)
19
16
  if @print_mode == :percentage
20
- puts "--> #{task}: #{(done.to_f/goal * 100).round}%"
17
+ puts "--> #{task}: #{(done_percent * 100).floor}%"
21
18
  else
22
19
  puts "--> #{task}:"
23
- done_count = (done.to_f/goal * 20).to_i
24
- todo_count = 20 - done_count
25
- puts " |#{"+" * (done_count)}|#{"-" * todo_count}|"
20
+ done_string = "+" * (done_percent * @bar_size)
21
+ todo_string = "-" * (@bar_size - done_string.length)
22
+ if done == 0
23
+ splitter = '-'
24
+ elsif done == goal
25
+ splitter = '+'
26
+ else
27
+ splitter = '|'
28
+ end
29
+ puts " |#{done_string}#{splitter}#{todo_string}|"
26
30
  end
27
31
  end
28
32
  puts
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bars
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robert Fletcher