progressrus 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9b39a0c76542e10e41e85fd7054b5dab25a8c77
4
- data.tar.gz: b009a97188d3e5f310a812d032a7a968b8456350
3
+ metadata.gz: e9443b1b626649e1d9e17aa2ed9ef9354312bc78
4
+ data.tar.gz: 4e9bd7b04d2f47975bfc9bbfa96f36ced10e3ccf
5
5
  SHA512:
6
- metadata.gz: 50103f860e60a3556e324947be3358fd1d3239a78e83847b7d0f1177452932f5523dc76a2718ea3ab94228e3884f3520e69b3bc0d76473eb451a7dc19cc73827
7
- data.tar.gz: 2217d65aa3758df8cf690486163ab8f761a3b3a91687bcbef3c38a659c2099c2e3188d5b1358d404cd4cdfe987036e7a4258b9b0764bccf1654fda867c8f94df
6
+ metadata.gz: f8093bed5b344ff65be4f5bc8b0ec207eb1984c4fb7f45ea629e0c6d7306f2a6fbfc0cf645bd7d73940b3ec8368ffb87235edac040c2805fe28c0113d70b9908
7
+ data.tar.gz: 71e0a98fc087451ad400f72c16d3c461873a93c75ba27ec90231dae1610ecc5b724e346603a51b06f6de64889360dc9769e441d3dec69c7130ff7500a8d38b49
@@ -42,7 +42,7 @@ class Progressrus
42
42
  completed_at: nil, started_at: nil, count: 0, failed_at: nil,
43
43
  error_count: 0, persist: false, expires_at: nil)
44
44
 
45
- raise ArgumentError, "Total cannot be zero or negative." if total && total <= 0
45
+ raise ArgumentError, "Total cannot be negative." if total && total < 0
46
46
 
47
47
  @name = name || id
48
48
  @scope = Array(scope).map(&:to_s)
@@ -120,7 +120,7 @@ class Progressrus
120
120
  end
121
121
 
122
122
  def total=(new_total)
123
- raise ArgumentError, "Total cannot be zero or negative." if new_total <= 0
123
+ raise ArgumentError, "Total cannot be negative." if new_total < 0
124
124
  @total = new_total
125
125
  end
126
126
 
@@ -133,7 +133,11 @@ class Progressrus
133
133
  end
134
134
 
135
135
  def percentage
136
- count.to_f / total
136
+ if total > 0
137
+ count.to_f / total
138
+ else
139
+ 1.0
140
+ end
137
141
  end
138
142
 
139
143
  def eta(now: Time.now)
@@ -1,3 +1,3 @@
1
1
  class Progressrus
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -110,10 +110,17 @@ class ProgressrusTest < Minitest::Test
110
110
  assert_equal 1.2, @progress.percentage
111
111
  end
112
112
 
113
- def test_percentage_should_be_0_if_total_0
113
+ def test_percentage_should_be_0_if_count_0
114
114
  assert_equal 0, @progress.percentage
115
115
  end
116
116
 
117
+ def test_percentage_should_be_1_if_total_0
118
+ progress = Progressrus.new(total: 0)
119
+ assert_equal 1, progress.percentage
120
+ progress.tick
121
+ assert_equal 1, progress.percentage
122
+ end
123
+
117
124
  def test_elapsed_should_return_the_delta_between_now_and_started_at
118
125
  time = Time.now
119
126
  @progress.tick(10, now: time - 10)
@@ -168,10 +175,9 @@ class ProgressrusTest < Minitest::Test
168
175
  assert_equal now.to_i, @progress.completed_at.to_i
169
176
  end
170
177
 
171
- def test_should_not_be_able_to_set_total_to_0
172
- assert_raises ArgumentError do
173
- @progress.total = 0
174
- end
178
+ def test_should_be_able_to_set_total_to_0
179
+ @progress.total = 0
180
+ assert_equal 0, @progress.total
175
181
  end
176
182
 
177
183
  def test_should_not_be_able_to_set_total_to_a_negative_number
@@ -199,10 +205,9 @@ class ProgressrusTest < Minitest::Test
199
205
  @progress.complete
200
206
  end
201
207
 
202
- def test_should_not_be_able_to_initialize_with_total_0
203
- assert_raises ArgumentError do
204
- Progressrus.new(total: 0)
205
- end
208
+ def test_should_be_able_to_initialize_with_total_0
209
+ progress = Progressrus.new(total: 0)
210
+ assert_equal 0, progress.total
206
211
  end
207
212
 
208
213
  def test_should_not_be_able_to_initialize_with_total_as_a_negative_number
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progressrus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Eskildsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-26 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 2.4.5.1
189
+ rubygems_version: 2.2.3
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Monitor the progress of remote, long-running jobs.