fortschritt 0.1.1 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40f95f33dc74042947092df0d7714c9a3959278a
4
- data.tar.gz: f95652c2c15304e4b578d5c21b2917982d342f19
3
+ metadata.gz: d8161d0b7307f0b9ef7fddc1e98d9a3ddcd5769d
4
+ data.tar.gz: 7b54ad9dd0a8724fa9935657d5681223d7993163
5
5
  SHA512:
6
- metadata.gz: b15d6a18e3a78680a296f5fbbc52dbc276ca2781e89ff31ecfb820375058d29af4b16c023a4ae56fa359bed0676c1fc9539ee14c0e660d123a41d887413a3540
7
- data.tar.gz: 5d52b1d41c8e98a8e44ff70a42b0784aa5db6d605e2c2f20ef98322e8ce04330258a4ea90fbb3f1abbe85451cff3553bb7254c66a641343da1072caa93dfe5ee
6
+ metadata.gz: 2c02bd0c6119fcfd14af27eebbfcd38243c32eba448492df03a854296a1c39086172207abdf35ad9378a5ecd9d147e93862ce7cef86ed50ad771dc614ae3bab5
7
+ data.tar.gz: 166b0d58bf5cddbcc6b3e0fc579acc2c394574e7a0ec37a60819c1b4b094819e9b5baaba4d6109582913c03d25739d3af161bfb07f27a19d6b60bcc51ebe2d8c
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # Fortschritt
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fortschritt`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
3
  ## Installation
8
4
 
9
5
  Add this line to your application's Gemfile:
@@ -22,15 +18,21 @@ Or install it yourself as:
22
18
 
23
19
  ## Usage
24
20
 
25
- TODO: Write usage instructions here
21
+ Start a progress bar by calling `with_fortschritt` on an `Enumerable` or an `ActiveRecord::Relation`.
26
22
 
27
- ## Development
23
+ It will create a new progress bar, that will be incremented by calling `Fortschritt.increment`.
28
24
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+ However, for convenience you can call `#fortschritt` on your iterated objects as well. It will call `Fortschritt.increment` and return `self`, so you can chain it up nicely.
30
26
 
31
- 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).
27
+ ```ruby
28
+ User.all.with_fortschritt.find_each do |user|
29
+ user.fortschritt.valid?
30
+ end
31
+
32
+ # will print something like this: 1616/145096 → 00:13:21 → ETA 2016-02-04 18:11:50
33
+ ```
32
34
 
33
35
  ## Contributing
34
36
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fortschritt.
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/xijo/fortschritt.
36
38
 
data/Rakefile CHANGED
@@ -1,6 +1,15 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :default => :spec
7
+
8
+ task :demo do
9
+ require_relative 'lib/fortschritt'
10
+ count = ENV['COUNT'] ? ENV['COUNT'].to_i : 1000
11
+ (1..count).to_a.with_fortschritt.each do |i|
12
+ i.fortschritt
13
+ sleep rand/50
14
+ end
15
+ end
@@ -7,6 +7,7 @@ module Fortschritt
7
7
  @done = 0
8
8
  @updated_at = Time.now
9
9
  @average_seconds = 0
10
+ @started_at = Time.now
10
11
  end
11
12
 
12
13
  def increment
@@ -35,9 +36,12 @@ module Fortschritt
35
36
  ((average_seconds * done) + value) / (done + 1)
36
37
  end
37
38
 
39
+ def total_elapsed_seconds
40
+ Time.now - @started_at
41
+ end
42
+
38
43
  def print!
39
44
  Fortschritt.printer.print(self)
40
45
  end
41
-
42
46
  end
43
47
  end
@@ -9,10 +9,9 @@ module Fortschritt
9
9
  slice(meter),
10
10
  remaining(meter),
11
11
  eta(meter),
12
- ].join ' → '
12
+ finished_after(meter),
13
+ ].compact.join ' → '
13
14
  "\r#{result}#{eol(meter)}"
14
- # stream.print result
15
- # print "\r#{done}/#{total}, avg #{average.round(3)}, remaining #{remaining}"#, percent: #{?| * (percent / 10)}> #{percent}%"
16
15
  end
17
16
 
18
17
  def slice(meter)
@@ -24,18 +23,28 @@ module Fortschritt
24
23
  "ETA #{result.strftime "%Y-%m-%d %H:%M:%S"}"
25
24
  end
26
25
 
27
- def remaining(meter)
28
- mm, ss = meter.remaining_seconds.divmod(60)
29
- hh, mm = mm.divmod(60)
30
- dd, hh = hh.divmod(24)
26
+ def finished_after(meter)
27
+ meter.completed? or return
28
+ "took #{format_seconds(meter.total_elapsed_seconds)}"
29
+ end
31
30
 
32
- "%02d:%02d:%02d" % [hh, mm, ss]
33
- # "%d days, %d hours, %d minutes and %d seconds" % [dd, hh, mm, ss]
34
- #=> 3 days, 3 hours, 15 minutes and 21 seconds
31
+ def remaining(meter)
32
+ format_seconds meter.remaining_seconds
35
33
  end
36
34
 
37
35
  def eol(meter)
38
36
  meter.completed? ? "\n" : ''
39
37
  end
38
+
39
+ private
40
+
41
+ # "%d days, %d hours, %d minutes and %d seconds" % [dd, hh, mm, ss]
42
+ #=> 3 days, 3 hours, 15 minutes and 21 seconds
43
+ def format_seconds(seconds)
44
+ mm, ss = seconds.divmod(60)
45
+ hh, mm = mm.divmod(60)
46
+ dd, hh = hh.divmod(24)
47
+ "%02d:%02d:%02d" % [hh, mm, ss]
48
+ end
40
49
  end
41
50
  end
@@ -1,3 +1,3 @@
1
1
  module Fortschritt
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fortschritt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Opper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-08 00:00:00.000000000 Z
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,8 +92,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.4.5
95
+ rubygems_version: 2.5.1
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: non-fancy progress
99
99
  test_files: []
100
+ has_rdoc: