progbar 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/progbar.rb +6 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e808781707eb67c816b5e840347b5fd3e0d6d30d
4
- data.tar.gz: df328d8be8b0f112e04cec1cfd86ba4e2d4f1a22
3
+ metadata.gz: 57f66bb6df812a8370a3a2760b3e3adbaa2190a1
4
+ data.tar.gz: 3c5392504d6442558d411556539fbad1e1c54f55
5
5
  SHA512:
6
- metadata.gz: 6b8c41889347667c8b3fd366e7c39529321467ee691e3a98b1ed3b662e6008a455b075aa6893f5b82509eb95faed15b3540181dd695384fba181896f55d09259
7
- data.tar.gz: 846465861b768c90d91e12ef59c4b37bbc3da71360abf323be75755f93aa007f843110f2467a08b5e5efcb8eae72d5e2cc5de610c5b8c8e3d9c8a2c57f59b0ae
6
+ metadata.gz: 9328813deca16d895cbd48f807c1efea28e97e973934c5dc6a1aab203689d4aa1401010426f983ce5e069f419c652d873672cc1abf703c9d9ee54c0145767db6
7
+ data.tar.gz: f955274acc8fefdb79e755c08b02380b4439489c056e1770f36e0dc628241a2b5b68effb1960c38fd0d08b751d43ab7057e9bdd22370ec3a4b5899b464ae3204
@@ -1,24 +1,26 @@
1
1
  class Array
2
2
  def prog_each(&block)
3
+ bar_length = (`tput cols` || 80).to_i - 30
3
4
  time_now = Time.now
4
5
  total = self.count
5
6
  last_flush = 0
6
7
  flush_time = 1
7
8
  self.each_with_index{|element, x|
8
9
  cur = (x+1) * 100 / total
9
- time_left = (((Time.now - time_now) * (100 - cur)) / cur).to_i
10
+ time_left = (((Time.now - time_now) * (100 - cur)).to_f / cur).ceil
10
11
  if (Time.now - last_flush).to_i >= flush_time or time_left < 1
11
12
  time_left_graceful = Time.at(time_left).utc.strftime("%H:%M:%S")
12
13
  if time_left > 86400
13
14
  time_left_graceful = res.split(":")
14
- time_left_graceful[0] = (time_left_graceful[0].to_i + days*24).to_s
15
+ time_left_graceful[0] = (time_left_graceful[0].to_i + days * 24).to_s
15
16
  time_left_graceful = time_left_graceful.join(":")
16
17
  end
17
18
  print "\r"
18
- print "[" + (["#"] * cur).join + (["-"] * (100-cur)).join + "] #{cur}% [#{time_left_graceful} left]"
19
+ cur_len = (bar_length * (x + 1)) / total
20
+ print "[" << (["#"] * cur_len).join << (["-"] * (bar_length - cur_len)).join << "] #{cur}% [#{time_left_graceful} left]"
19
21
  last_flush = Time.now
20
22
  end
21
- block.call(element) if block
23
+ block.call element if block
22
24
  }
23
25
  puts "\n"
24
26
  "Done."
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - anvyzhang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-13 00:00:00.000000000 Z
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Print progress bar for array iteration
14
14
  email: m@anvy.me