progbar 0.0.2

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. checksums.yaml +7 -0
  2. data/lib/progbar.rb +26 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e808781707eb67c816b5e840347b5fd3e0d6d30d
4
+ data.tar.gz: df328d8be8b0f112e04cec1cfd86ba4e2d4f1a22
5
+ SHA512:
6
+ metadata.gz: 6b8c41889347667c8b3fd366e7c39529321467ee691e3a98b1ed3b662e6008a455b075aa6893f5b82509eb95faed15b3540181dd695384fba181896f55d09259
7
+ data.tar.gz: 846465861b768c90d91e12ef59c4b37bbc3da71360abf323be75755f93aa007f843110f2467a08b5e5efcb8eae72d5e2cc5de610c5b8c8e3d9c8a2c57f59b0ae
data/lib/progbar.rb ADDED
@@ -0,0 +1,26 @@
1
+ class Array
2
+ def prog_each(&block)
3
+ time_now = Time.now
4
+ total = self.count
5
+ last_flush = 0
6
+ flush_time = 1
7
+ self.each_with_index{|element, x|
8
+ cur = (x+1) * 100 / total
9
+ time_left = (((Time.now - time_now) * (100 - cur)) / cur).to_i
10
+ if (Time.now - last_flush).to_i >= flush_time or time_left < 1
11
+ time_left_graceful = Time.at(time_left).utc.strftime("%H:%M:%S")
12
+ if time_left > 86400
13
+ time_left_graceful = res.split(":")
14
+ time_left_graceful[0] = (time_left_graceful[0].to_i + days*24).to_s
15
+ time_left_graceful = time_left_graceful.join(":")
16
+ end
17
+ print "\r"
18
+ print "[" + (["#"] * cur).join + (["-"] * (100-cur)).join + "] #{cur}% [#{time_left_graceful} left]"
19
+ last_flush = Time.now
20
+ end
21
+ block.call(element) if block
22
+ }
23
+ puts "\n"
24
+ "Done."
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: progbar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - anvyzhang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Print progress bar for array iteration
14
+ email: m@anvy.me
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/progbar.rb
20
+ homepage: https://github.com/anvyzhang/progbar
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Print progress bar for array iteration
44
+ test_files: []