console_progress 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c71df20be61e4883f8b00664151b2aff535caa89
4
+ data.tar.gz: d6e06f27d1fccf73dc9f3977845fae49bf822801
5
+ SHA512:
6
+ metadata.gz: 778670e005b3152761f97459942c9e9ad8c55ace597d52794a98433eb2ac115f6fbe36089cb3196cd1cab499477e69919146f087411fabdd7938a890b752e322
7
+ data.tar.gz: b4a3b1342d78688afa0a9d9f3a0596bd0a375a42e201b4c79f5c329d94d96bb1fe0d1d555ea377aa8febf9ee7e32c460ec231c5c7e71ecf3eb852aaea7ace6be
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /.ruby-version
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in console_progress.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ben Wiseley
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # ConsoleProgress
2
+
3
+ A simple gem to log progress on a job.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'console_progress'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install console_progress
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ prog = ConsoleProgress::ETA.new(5)
25
+ prog.start
26
+ 5.times do
27
+ puts prog.progress
28
+ sleep 2
29
+ end
30
+ ```
31
+
32
+ Would output something like:
33
+ ```
34
+ ETA: 1/5 Time Left 0.00h or 0.00m Took: 0.00s Avg: 0.00s
35
+ ETA: 2/5 Time Left 0.00h or 0.07m Took: 2.00s Avg: 1.00s
36
+ ETA: 3/5 Time Left 0.00h or 0.07m Took: 2.00s Avg: 1.34s
37
+ ETA: 4/5 Time Left 0.00h or 0.05m Took: 2.00s Avg: 1.50s
38
+ ETA: 5/5 Time Left 0.00h or 0.03m Took: 2.00s Avg: 1.60s
39
+ ```
40
+
41
+ Initialize with `number of steps`. Start it. Call `.progress` to move up a step.
42
+
43
+ You can override the default message prefix with `prog.message_prefix = 'Bob'`
44
+
45
+ You can override format by putting anything in `ConsoleProgress::ATTR` in a string with `{{}}` around it. Example:
46
+
47
+ ```ruby
48
+ prog = ConsoleProgress.new(100, format: '{{step}}/{{steps}}'
49
+ or
50
+ set it later prog.format = '{{step}}/{{steps}}'
51
+ ```
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wiseleyb/console_progress.
62
+
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
67
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "console_progress"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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 'console_progress/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "console_progress"
8
+ spec.version = ConsoleProgress::VERSION
9
+ spec.authors = ["Ben Wiseley"]
10
+ spec.email = ["wiseleyb@gmail.com"]
11
+
12
+ spec.summary = 'Simple progress gem for use in logs/console'
13
+ spec.description = 'Simple progress gem for use in logs/console'
14
+ spec.homepage = 'https://github.com/wiseleyb/console_progress'
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,53 @@
1
+ require "console_progress/version"
2
+
3
+ module ConsoleProgress
4
+ class ETA
5
+ ATTR = [:steps, :step, :step_time, :times,
6
+ :avg_time, :format, :start_time,
7
+ :hours, :minutes, :seconds,
8
+ :message_prefix]
9
+
10
+ attr_accessor *ATTR
11
+
12
+ def initialize(steps, format: nil)
13
+ @steps = steps
14
+ @format = format
15
+ @message_prefix = 'ETA'
16
+ @format ||= "{{message_prefix}}: {{step}}/{{steps}} "\
17
+ "Time Left {{hours}}h or {{minutes}}m "\
18
+ "Took: {{step_time}}s Avg: {{avg_time}}s"
19
+ @step = 0
20
+ @times = []
21
+ end
22
+
23
+ def start
24
+ @start_time = Time.now
25
+ @step_time_start = @start_time
26
+ end
27
+
28
+ def progress(msg = nil, current_step: @step)
29
+ @message_prefix = msg if msg
30
+ t = Time.now
31
+ @step_time = t - @step_time_start
32
+ @times << @step_time
33
+ @avg_time = @times.reduce(0, :+) / @times.size
34
+ steps_left = @steps - @step
35
+ @step = current_step + 1
36
+ @seconds = steps_left * @avg_time
37
+ @minutes = '%.2f' % (@seconds / 60)
38
+ @hours = '%.2f' % (@seconds / 60 / 60)
39
+ @step_time = '%.2f' % @step_time
40
+ @avg_time = '%.2f' % @avg_time
41
+ @step_time_start = t
42
+ log
43
+ end
44
+
45
+ def log(msg = @message_prefix)
46
+ out = @format.dup
47
+ ATTR.each do |m|
48
+ out.gsub!("{{#{m}}}", send(m).to_s)
49
+ end
50
+ out
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module ConsoleProgress
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: console_progress
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Wiseley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-15 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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
+ description: Simple progress gem for use in logs/console
42
+ email:
43
+ - wiseleyb@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - console_progress.gemspec
56
+ - lib/console_progress.rb
57
+ - lib/console_progress/version.rb
58
+ homepage: https://github.com/wiseleyb/console_progress
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.5.1
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Simple progress gem for use in logs/console
82
+ test_files: []