fortschritt 0.1.1 → 0.2.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 +4 -4
- data/README.md +11 -9
- data/Rakefile +11 -2
- data/lib/fortschritt/meter.rb +5 -1
- data/lib/fortschritt/printer.rb +19 -10
- data/lib/fortschritt/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8161d0b7307f0b9ef7fddc1e98d9a3ddcd5769d
|
4
|
+
data.tar.gz: 7b54ad9dd0a8724fa9935657d5681223d7993163
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c02bd0c6119fcfd14af27eebbfcd38243c32eba448492df03a854296a1c39086172207abdf35ad9378a5ecd9d147e93862ce7cef86ed50ad771dc614ae3bab5
|
7
|
+
data.tar.gz: 166b0d58bf5cddbcc6b3e0fc579acc2c394574e7a0ec37a60819c1b4b094819e9b5baaba4d6109582913c03d25739d3af161bfb07f27a19d6b60bcc51ebe2d8c
|
data/README.md
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# Fortschritt
|
2
2
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fortschritt`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
3
|
## Installation
|
8
4
|
|
9
5
|
Add this line to your application's Gemfile:
|
@@ -22,15 +18,21 @@ Or install it yourself as:
|
|
22
18
|
|
23
19
|
## Usage
|
24
20
|
|
25
|
-
|
21
|
+
Start a progress bar by calling `with_fortschritt` on an `Enumerable` or an `ActiveRecord::Relation`.
|
26
22
|
|
27
|
-
|
23
|
+
It will create a new progress bar, that will be incremented by calling `Fortschritt.increment`.
|
28
24
|
|
29
|
-
|
25
|
+
However, for convenience you can call `#fortschritt` on your iterated objects as well. It will call `Fortschritt.increment` and return `self`, so you can chain it up nicely.
|
30
26
|
|
31
|
-
|
27
|
+
```ruby
|
28
|
+
User.all.with_fortschritt.find_each do |user|
|
29
|
+
user.fortschritt.valid?
|
30
|
+
end
|
31
|
+
|
32
|
+
# will print something like this: 1616/145096 → 00:13:21 → ETA 2016-02-04 18:11:50
|
33
|
+
```
|
32
34
|
|
33
35
|
## Contributing
|
34
36
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/xijo/fortschritt.
|
36
38
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
6
|
task :default => :spec
|
7
|
+
|
8
|
+
task :demo do
|
9
|
+
require_relative 'lib/fortschritt'
|
10
|
+
count = ENV['COUNT'] ? ENV['COUNT'].to_i : 1000
|
11
|
+
(1..count).to_a.with_fortschritt.each do |i|
|
12
|
+
i.fortschritt
|
13
|
+
sleep rand/50
|
14
|
+
end
|
15
|
+
end
|
data/lib/fortschritt/meter.rb
CHANGED
@@ -7,6 +7,7 @@ module Fortschritt
|
|
7
7
|
@done = 0
|
8
8
|
@updated_at = Time.now
|
9
9
|
@average_seconds = 0
|
10
|
+
@started_at = Time.now
|
10
11
|
end
|
11
12
|
|
12
13
|
def increment
|
@@ -35,9 +36,12 @@ module Fortschritt
|
|
35
36
|
((average_seconds * done) + value) / (done + 1)
|
36
37
|
end
|
37
38
|
|
39
|
+
def total_elapsed_seconds
|
40
|
+
Time.now - @started_at
|
41
|
+
end
|
42
|
+
|
38
43
|
def print!
|
39
44
|
Fortschritt.printer.print(self)
|
40
45
|
end
|
41
|
-
|
42
46
|
end
|
43
47
|
end
|
data/lib/fortschritt/printer.rb
CHANGED
@@ -9,10 +9,9 @@ module Fortschritt
|
|
9
9
|
slice(meter),
|
10
10
|
remaining(meter),
|
11
11
|
eta(meter),
|
12
|
-
|
12
|
+
finished_after(meter),
|
13
|
+
].compact.join ' → '
|
13
14
|
"\r#{result}#{eol(meter)}"
|
14
|
-
# stream.print result
|
15
|
-
# print "\r#{done}/#{total}, avg #{average.round(3)}, remaining #{remaining}"#, percent: #{?| * (percent / 10)}> #{percent}%"
|
16
15
|
end
|
17
16
|
|
18
17
|
def slice(meter)
|
@@ -24,18 +23,28 @@ module Fortschritt
|
|
24
23
|
"ETA #{result.strftime "%Y-%m-%d %H:%M:%S"}"
|
25
24
|
end
|
26
25
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
def finished_after(meter)
|
27
|
+
meter.completed? or return
|
28
|
+
"took #{format_seconds(meter.total_elapsed_seconds)}"
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
#=> 3 days, 3 hours, 15 minutes and 21 seconds
|
31
|
+
def remaining(meter)
|
32
|
+
format_seconds meter.remaining_seconds
|
35
33
|
end
|
36
34
|
|
37
35
|
def eol(meter)
|
38
36
|
meter.completed? ? "\n" : ''
|
39
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# "%d days, %d hours, %d minutes and %d seconds" % [dd, hh, mm, ss]
|
42
|
+
#=> 3 days, 3 hours, 15 minutes and 21 seconds
|
43
|
+
def format_seconds(seconds)
|
44
|
+
mm, ss = seconds.divmod(60)
|
45
|
+
hh, mm = mm.divmod(60)
|
46
|
+
dd, hh = hh.divmod(24)
|
47
|
+
"%02d:%02d:%02d" % [hh, mm, ss]
|
48
|
+
end
|
40
49
|
end
|
41
50
|
end
|
data/lib/fortschritt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fortschritt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johannes Opper
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -92,8 +92,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.5.1
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: non-fancy progress
|
99
99
|
test_files: []
|
100
|
+
has_rdoc:
|