formatador 0.1.4 → 0.1.5

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.
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'formatador'
16
- s.version = '0.1.4'
17
- s.date = '2011-05-20'
16
+ s.version = '0.1.5'
17
+ s.date = '2011-07-05'
18
18
  s.rubyforge_project = 'formatador'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'formatador', 'progressbar')
3
3
 
4
4
  class Formatador
5
5
 
6
- VERSION = '0.1.4'
6
+ VERSION = '0.1.5'
7
7
 
8
8
  STYLES = {
9
9
  :"\/" => "0",
@@ -24,18 +24,29 @@ class Formatador
24
24
  output << options[:label]
25
25
  end
26
26
 
27
- padding = ' ' * (total.to_s.size - current.to_s.size)
28
- output << "[#{color}]#{padding}#{current}/#{total}[/]"
27
+ # width
28
+ # we are going to write a string that looks like " current/total"
29
+ # It would be nice if it were left padded with spaces in such a way that
30
+ # it puts the progress bar in a constant place on the page. This witdh
31
+ # calculation allows for the "current" string to be up to two characters
32
+ # longer than the "total" string without problems. eg- current =
33
+ # 9.99, total = 10
34
+ padding = total.to_s.size * 2 + 3
35
+
36
+ output << "[#{color}]%#{padding}s[/]" % "#{current}/#{total}"
29
37
 
30
38
  percent = current.to_f / total.to_f
39
+ percent = 0 if percent < 0
40
+ percent = 1 if percent > 1
41
+
31
42
  done = '*' * (percent * width).ceil
32
43
  remaining = ' ' * (width - done.length)
33
44
  output << "[_white_]|[/][#{color}][_#{color}_]#{done}[/]#{remaining}[_white_]|[/]"
34
45
 
35
46
  if started_at
36
47
  elapsed = Time.now - started_at
37
- minutes = (elapsed / 60).round.to_s
38
- seconds = (elapsed % 60).round.to_s
48
+ minutes = (elapsed / 60).truncate.to_s
49
+ seconds = (elapsed % 60).truncate.to_s
39
50
  output << "#{minutes}:#{'0' if seconds.size < 2}#{seconds}"
40
51
  end
41
52
 
@@ -20,6 +20,7 @@ output = <<-OUTPUT
20
20
  +--------+
21
21
  | \e[1mheader\e[0m |
22
22
  +--------+
23
+ +--------+
23
24
  OUTPUT
24
25
 
25
26
  tests("#display_table([], [:header])").returns(output) do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatador
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - geemus (Wesley Beary)
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-20 00:00:00 -07:00
18
+ date: 2011-07-05 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency