progress 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,9 +18,8 @@ begin
18
18
  task 'ghost' do
19
19
  gem_path = Pathname(Gem.searcher.find(name).full_gem_path)
20
20
  current_path = Pathname('.').expand_path
21
- cmd = gem_path.writable? && gem_path.parent.writable? ? %w() : %w(sudo)
22
- system(*cmd + %W[rm -r #{gem_path}])
23
- system(*cmd + %W[ln -s #{current_path} #{gem_path}])
21
+ system('rm', '-r', gem_path)
22
+ system('ln', '-s', current_path, gem_path)
24
23
  end
25
24
 
26
25
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
data/lib/progress.rb CHANGED
@@ -10,6 +10,11 @@ class Progress
10
10
  attr_accessor :title, :current, :total
11
11
  attr_reader :current_step
12
12
  def initialize(title, total)
13
+ if title.is_a?(Numeric) && total.nil?
14
+ title, total = nil, title
15
+ elsif total.nil?
16
+ total = 1
17
+ end
13
18
  total = Float(total)
14
19
  @title, @current, @total = title, 0.0, total == 0.0 ? 1.0 : total
15
20
  end
@@ -62,7 +67,7 @@ class Progress
62
67
  # Progress.lines = true
63
68
  # ==== To force highlight
64
69
  # Progress.highlight = true
65
- def start(title, total = 1)
70
+ def start(title = nil, total = nil)
66
71
  levels << new(title, total)
67
72
  print_message(true)
68
73
  if block_given?
@@ -152,7 +157,7 @@ class Progress
152
157
  levels.reverse.each do |l|
153
158
  current = l.to_f(inner)
154
159
  value = current == 0 ? '......' : "#{'%5.1f' % (current * 100.0)}%"
155
- messages << "#{l.title}: #{!highlight? || value == '100.0%' ? value : "\e[1m#{value}\e[0m"}"
160
+ messages << "#{"#{l.title}: " if l.title}#{!highlight? || value == '100.0%' ? value : "\e[1m#{value}\e[0m"}"
156
161
  inner = current
157
162
  end
158
163
  message = messages.reverse * ' > '
@@ -181,7 +186,7 @@ require 'progress/integer'
181
186
 
182
187
  # like Pathname
183
188
  module Kernel
184
- def Progress(title, total = 1, &block)
189
+ def Progress(title = nil, total = nil, &block)
185
190
  Progress.start(title, total, &block)
186
191
  end
187
192
  private :Progress
@@ -9,7 +9,7 @@ module Enumerable
9
9
  # [1, 2, 3].with_progress('Numbers').each_cons(2) do |numbers|
10
10
  # p numbers
11
11
  # end
12
- def with_progress(title)
12
+ def with_progress(title = nil)
13
13
  Progress::WithProgress.new(self, title)
14
14
  end
15
15
 
@@ -18,8 +18,8 @@ module Enumerable
18
18
  # [1, 2, 3].each_with_progress('Numbers') do |number|
19
19
  # sleep(number)
20
20
  # end
21
- def each_with_progress(title, *args, &block)
22
- with_progress(title).each(*args, &block)
21
+ def each_with_progress(title = nil, &block)
22
+ with_progress(title).each(&block)
23
23
  end
24
24
 
25
25
  # note that Progress.step is called automatically
@@ -27,8 +27,8 @@ module Enumerable
27
27
  # [1, 2, 3].each_with_index_and_progress('Numbers') do |number, index|
28
28
  # sleep(number)
29
29
  # end
30
- def each_with_index_and_progress(title, *args, &block)
31
- with_progress(title).each_with_index(*args, &block)
30
+ def each_with_index_and_progress(title, &block)
31
+ with_progress(title).each_with_index(&block)
32
32
  end
33
33
 
34
34
  end
@@ -4,8 +4,8 @@ class Integer
4
4
  # 100.times_with_progress('Numbers') do |number|
5
5
  # sleep(number)
6
6
  # end
7
- def times_with_progress(name)
8
- Progress.start(name, self) do
7
+ def times_with_progress(title = nil)
8
+ Progress.start(title, self) do
9
9
  times do |i|
10
10
  yield i
11
11
  Progress.step
data/progress.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{progress}
8
- s.version = "0.2.2"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Boba Fat"]
12
- s.date = %q{2010-01-20}
12
+ s.date = %q{2010-11-13}
13
13
  s.extra_rdoc_files = [
14
14
  "README.rdoc"
15
15
  ]
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
30
30
  s.homepage = %q{http://github.com/toy/progress}
31
31
  s.rdoc_options = ["--charset=UTF-8"]
32
32
  s.require_paths = ["lib"]
33
- s.rubygems_version = %q{1.3.5}
33
+ s.rubygems_version = %q{1.3.7}
34
34
  s.summary = %q{Show progress of long running tasks}
35
35
  s.test_files = [
36
36
  "spec/progress_spec.rb",
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
41
41
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
42
  s.specification_version = 3
43
43
 
44
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
45
  else
46
46
  end
47
47
  else
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Boba Fat
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-01-20 00:00:00 +03:00
18
+ date: 2010-11-13 00:00:00 +03:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -44,21 +50,27 @@ rdoc_options:
44
50
  require_paths:
45
51
  - lib
46
52
  required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
47
54
  requirements:
48
55
  - - ">="
49
56
  - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
50
60
  version: "0"
51
- version:
52
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
53
63
  requirements:
54
64
  - - ">="
55
65
  - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
56
69
  version: "0"
57
- version:
58
70
  requirements: []
59
71
 
60
72
  rubyforge_project:
61
- rubygems_version: 1.3.5
73
+ rubygems_version: 1.3.7
62
74
  signing_key:
63
75
  specification_version: 3
64
76
  summary: Show progress of long running tasks