popro 0.1.1 → 0.1.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -6
  3. data/lib/popro/progress.rb +22 -3
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce1a842c500f314f3ed8ba0e7e9deb5a4ece7cbf81ea11563664336cf35ddcd1
4
- data.tar.gz: 3d313f96ff1b5dda33e51ec994ee592447e957201ebf059b86caef3d0d830c53
3
+ metadata.gz: c0ed84ff76f7db2ab74b649ef29f62dab630f3b12dc0e2a8cf011382814d9396
4
+ data.tar.gz: ff292d589ecdfd671fe1136079611bc45ccbec5c262c2b831baef59799732de9
5
5
  SHA512:
6
- metadata.gz: d68080c7a53d74a50e15fdb252f7aacbc57616a9de4aeb12bff133f715c347f07cdb6c9e2643d769a48babf01c6eb127e9e2dd6bdcd3d028d460efda34068d3b
7
- data.tar.gz: f699ce90d06692c3ccfa71a342e1eceda39456c0599891c535f024ff0b64cec5eb8c8a56d5d91f83d96f300d5009c8098a7f73cdcb62ccf778fbc0a7feb0b96b
6
+ metadata.gz: 810c7e4925421c86e3585d429a948f50de6ea913042b9c3edc6d13a63557286e9ca83f2d6c973700388d5934aff9097071b78db7c6b0c3eb162e6fba6666e566
7
+ data.tar.gz: ffab387b8fbed5b19e88d58d97a3001cff0f7855b9154754acd114c6bdd53bb846085d47fb04f7ed7c3a3972315f400a71dbbb6e28519a45b30243df39180f4a
data/README.md CHANGED
@@ -1,13 +1,20 @@
1
1
  # Po'Pro: The Poor-Man's Progress Indicator
2
2
 
3
+ [![Version](https://badge.fury.io/rb/popro.svg)](https://badge.fury.io/rb/popro)
4
+ [![Tests](https://github.com/MikeSmithEU/PoPro/workflows/Code%20quality%20&%20unit%20tests/badge.svg)](https://github.com/MikeSmithEU/PoPro/actions?query=workflow%3A%22Code+quality+%26+unit+tests%22)
5
+
6
+ ## Current TODOs
7
+
8
+ - [ ] properly update documentation
9
+ - [ ] simplify some stuff (each0?)
10
+ - [ ] 100% code coverage
11
+
3
12
  ## Why?
4
13
 
5
14
  Easier and cleaner progress indication.
6
15
 
7
16
  ## How?
8
17
 
9
- TODO: properly update documentation, simplify some stuff. 100% code coverage
10
-
11
18
  ### Basic usage
12
19
 
13
20
  The invocation `Popro#did(yielded)` is used to signify that one step in progress has been finished.
@@ -263,11 +270,11 @@ end
263
270
  ## Formatters
264
271
 
265
272
  You can set your own formatters using `Popro#formatter(&block)`. Each formatter can be a `Proc`, `block` or
266
- class implementing the `call` method (e.g. the `PoproFormatter::*` classes).
273
+ class implementing the `call` method (e.g. the `Popro::Formatter::*` classes).
267
274
 
268
275
  The formatter will be invoked with 2 arguments:
269
276
 
270
- 1. `info`, an instance of `PoproInfo` containing e.g. `current` and `total`.
277
+ 1. `info`, an instance of `Popro::Info` containing e.g. `current` and `total`.
271
278
  2. `yielded`, whatever was passed to the `Popro#did` method.
272
279
 
273
280
  It can also be used inside blocks.
@@ -315,7 +322,7 @@ would output:
315
322
 
316
323
  Indicator classes are responsible for communicating the progress (or not, as the case may be).
317
324
 
318
- It is possible to provide your own "indicators" or use one of the provided ones (see `PoproIndicator` module).
325
+ It is possible to provide your own "indicators" or use one of the provided ones (see `Popro::Indicator` module).
319
326
 
320
- The default `PoproIndicator` class is `PoproIndicator.default` (which returns an instance of `PoproIndicator::Stream`), which outputs the progress to STDOUT each time `Popro#did` or `Popro#will` is called.
327
+ The default `Popro::Indicator` class is `Popro::Indicator.default` (which returns an instance of `Popro::Indicator::Stream`), which outputs the progress to STDOUT each time `Popro#did` or `Popro#will` is called.
321
328
 
@@ -6,17 +6,24 @@ module Popro
6
6
  require_relative 'info'
7
7
  require_relative 'indicator'
8
8
 
9
+ DEFAULT_OPTIONS ||= {
10
+ total: 0,
11
+ current: 0,
12
+ }.freeze
13
+
9
14
  attr_reader :context
10
15
 
11
16
  def initialize(**options)
17
+ options.merge!(DEFAULT_OPTIONS)
18
+
12
19
  @started = false
20
+
13
21
  @info = Info.new(total: options.delete(:total), current: options.delete(:current))
14
22
 
15
23
  options[:step] ||= (block_given? ? 0 : 1)
16
- options[:progress] = self
17
- options[:info] = @info
18
- options[:indicator] = Indicator.default unless options.key? :indicator
24
+ indicator = Indicator.default unless options.key? :indicator
19
25
 
26
+ options.merge!(progress: self, info: @info, indicator: indicator)
20
27
  @context = Context.new(**options)
21
28
 
22
29
  register_aliases
@@ -26,6 +33,12 @@ module Popro
26
33
  done
27
34
  end
28
35
 
36
+ # increase the total
37
+ def add(amount)
38
+ @info.total += amount
39
+ self
40
+ end
41
+
29
42
  private
30
43
 
31
44
  def register_aliases
@@ -35,6 +48,12 @@ module Popro
35
48
  @context.public_send(method_name, *args, &block)
36
49
  end
37
50
  end
51
+
52
+ %i[current total].each do |method_name|
53
+ define_method method_name do
54
+ @info.public_send(method_name)
55
+ end
56
+ end
38
57
  end
39
58
  end
40
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: popro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - MikeSmithEU