tiny_progress_bar 1.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.
- checksums.yaml +7 -0
- data/lib/tiny_progress_bar.rb +41 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1574f64c91ea6b74ba5104a787fa91a0cf86b317
|
4
|
+
data.tar.gz: 757abb00781bd97e18367113abf020ca2b980808
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4da3ea639794c3bbb4676b92514d9c35cfcdeb1a9d02e23bdef7f5d51bbef2ef0c9a7ea701bf73aab8e5010e4bece34a927a9d88fce45bdcc2fa2156c99e675
|
7
|
+
data.tar.gz: 91bf0bdd2c4149148882038d6e498b9797bd52a79448067f3dc0b685118bbcfb7d8931c0ba000241b801adf79a1d9dbfa64d707da06141a1b2286571442df80e
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module TinyProgressBar
|
2
|
+
def self.print options = {}
|
3
|
+
return @options = nil if options == :reset or options[:reset]
|
4
|
+
(@options ||= {
|
5
|
+
count: 0,
|
6
|
+
size: 100,
|
7
|
+
filled: '*',
|
8
|
+
empty: ' ',
|
9
|
+
precision: 0,
|
10
|
+
message: "Complete!",
|
11
|
+
opener: "[",
|
12
|
+
closer: "]",
|
13
|
+
last: nil,
|
14
|
+
out: $stdout
|
15
|
+
}).merge! options do |_, o, n| n.nil? ? o : n end
|
16
|
+
@options[:before] = options[:before]
|
17
|
+
@options[:after] = options[:after]
|
18
|
+
count = (@options[:count] = @options[:count] ? @options[:count] + 1 : 1)
|
19
|
+
size = @options[:size]
|
20
|
+
filled = @options[:filled]
|
21
|
+
empty = @options[:empty]
|
22
|
+
opener = @options[:opener]
|
23
|
+
closer = @options[:closer]
|
24
|
+
precision = @options[:precision]
|
25
|
+
max = @options[:max]
|
26
|
+
ratio = count.to_f / max.to_f
|
27
|
+
percentage = precision ? (ratio * 100.0).round(precision) : (ratio * 100.0)
|
28
|
+
filled_size = (ratio * size).floor.to_i
|
29
|
+
empty_size = size - filled_size
|
30
|
+
@options[:out].print "\b" * (@options[:last] || 0)
|
31
|
+
str = "#{(@options[:before] || "")}#{opener}" + filled * filled_size + empty * empty_size + "#{closer} #{percentage}% (#{count}/#{max})#{(@options[:after] || "")}"
|
32
|
+
@options[:out].print str
|
33
|
+
@options[:last] = str.length
|
34
|
+
if count == max
|
35
|
+
puts " #{@options[:message]}"
|
36
|
+
@options[:count] = 0
|
37
|
+
@options[:last] = 0
|
38
|
+
end
|
39
|
+
@options
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tiny_progress_bar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sylvain Leclercq
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: "A simple progress bar for time consuming applications. \nCall TinyProgressBar::print(max:
|
14
|
+
max_number). \nPersonalisation options available."
|
15
|
+
email: maisbiensurqueoui@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/tiny_progress_bar.rb
|
21
|
+
homepage: http://www.github.com/de-passage/tiny_progress_bar.rb
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.4.8
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: A tiny progress_bar
|
45
|
+
test_files: []
|