gain 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/gain.gemspec +24 -0
- data/lib/gain/version.rb +3 -0
- data/lib/gain.rb +32 -0
- data/spec/gain_spec.rb +19 -0
- data/spec/spec_helper.rb +8 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a58995916e8b75c8388d19dffc6040676ad4e289
|
4
|
+
data.tar.gz: dd4231364de24fead2c9ff253145f6bc9de9e5e8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d46263b8375de9f1bc99258f0f0c546f60583306a68480202b7bdb879eeb47df9f52e23659e69d6e2484a0d67b4725620980486039982cadfb03858b7a5b3864
|
7
|
+
data.tar.gz: bd97b5c2c50cdc27903eac7fd2ce7cabb058b1fcb384dd36691d649995fd9b8eb9d3f1ebbd034f3647852d0fb84510d4fe96fdab14a6e5e16a3d4078dd2f0a6c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Sukrit Sunama
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Sukit Sunama
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Gain
|
2
|
+
|
3
|
+
Simple printed progress style for ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'gain'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install gain
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gain = Gain.new :title => "Start 10,000 Progress", :total => 10000, :progress_print => 1
|
25
|
+
|
26
|
+
# :title is optional
|
27
|
+
# :progress_print is option for percentage of progress interval print to console, by default this value is 1 (every progress gain 1% Gain will print it to console)
|
28
|
+
|
29
|
+
for i in 1..10000 do
|
30
|
+
gain.progress
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
## Demo
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
> Start 10,000 Progress
|
38
|
+
> 1%
|
39
|
+
> 2%
|
40
|
+
> 3%
|
41
|
+
...
|
42
|
+
...
|
43
|
+
...
|
44
|
+
> 100%
|
45
|
+
> Complete processed
|
46
|
+
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it ( https://github.com/Sunama/gain/fork )
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/gain.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gain/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gain"
|
8
|
+
spec.version = Gain::VERSION
|
9
|
+
spec.authors = ["Sukit Sunama"]
|
10
|
+
spec.email = ["sunama.sukrit@gmail.com"]
|
11
|
+
spec.summary = %q{Simple printed progress style for ruby.}
|
12
|
+
spec.description = %q{Simple printed progress style for ruby.}
|
13
|
+
spec.homepage = "https://github.com/Sunama/gain"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", '~> 3.1', '>= 3.1.0'
|
24
|
+
end
|
data/lib/gain/version.rb
ADDED
data/lib/gain.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "gain/version"
|
2
|
+
|
3
|
+
class Gain
|
4
|
+
attr_reader :title, :total, :progress_print
|
5
|
+
@@progress_count = 0
|
6
|
+
@@progress_mod
|
7
|
+
@@round
|
8
|
+
|
9
|
+
def initialize(args)
|
10
|
+
args.each do |k,v|
|
11
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
@@progress_count = 0
|
15
|
+
@progress_print = 1 if @progress_print == nil
|
16
|
+
@@progress_mod = @total * @progress_print.to_f / 100.0
|
17
|
+
@progress_print.to_s.include?(".") ? @@round = @progress_print.to_s.split(".")[1].length : @@round = 0
|
18
|
+
|
19
|
+
puts @title if @title != nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def progress
|
23
|
+
@@progress_count += 1
|
24
|
+
|
25
|
+
puts "#{(@@progress_count / @total.to_f * 100).round(@@round)}%" if @@progress_count % @@progress_mod == 0
|
26
|
+
finish_progress if @@progress_count == @total
|
27
|
+
end
|
28
|
+
|
29
|
+
def finish_progress
|
30
|
+
puts "Complete processed"
|
31
|
+
end
|
32
|
+
end
|
data/spec/gain_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gain do
|
4
|
+
it "test with no decimal" do
|
5
|
+
gain = Gain.new :title => "Start 10,000 Progress", :total => 10000, :progress_print => 1
|
6
|
+
|
7
|
+
for i in 1..10000 do
|
8
|
+
gain.progress
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "test with decimal" do
|
13
|
+
gain = Gain.new :title => "Start 10,000 Progress", :total => 10000, :progress_print => 0.1
|
14
|
+
|
15
|
+
for i in 1..10000 do
|
16
|
+
gain.progress
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sukit Sunama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 3.1.0
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '3.1'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.1.0
|
61
|
+
description: Simple printed progress style for ruby.
|
62
|
+
email:
|
63
|
+
- sunama.sukrit@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- ".rspec"
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- gain.gemspec
|
76
|
+
- lib/gain.rb
|
77
|
+
- lib/gain/version.rb
|
78
|
+
- spec/gain_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
homepage: https://github.com/Sunama/gain
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.2.2
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Simple printed progress style for ruby.
|
104
|
+
test_files:
|
105
|
+
- spec/gain_spec.rb
|
106
|
+
- spec/spec_helper.rb
|