popro 0.0.1 → 0.1.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
  SHA256:
3
- metadata.gz: 23e8aecacb06e0bfe98467ac74b74f0b5e90ddc65f57069ae4bf29bdc7073b8a
4
- data.tar.gz: 6a220ecf6de03a768aeed0d4998983ada21d037859a9deafe6263b4604b201d7
3
+ metadata.gz: ce1a842c500f314f3ed8ba0e7e9deb5a4ece7cbf81ea11563664336cf35ddcd1
4
+ data.tar.gz: 3d313f96ff1b5dda33e51ec994ee592447e957201ebf059b86caef3d0d830c53
5
5
  SHA512:
6
- metadata.gz: cb458d4d2a5169342ede984048be23c86d101db7546585e408e7470fe799f3344df4d2c691e42e43ff5ddd915e9af284a44ae59a7780890b06340a70a5e56419
7
- data.tar.gz: 6a8fc7aef7feec2b0c39af0f1478f1cebaf4ccb8667edcc0842d119019dec709998e2d0a3930869646b51a210f4758eaa2b721894b7a1b79d554f44294996ce3
6
+ metadata.gz: d68080c7a53d74a50e15fdb252f7aacbc57616a9de4aeb12bff133f715c347f07cdb6c9e2643d769a48babf01c6eb127e9e2dd6bdcd3d028d460efda34068d3b
7
+ data.tar.gz: f699ce90d06692c3ccfa71a342e1eceda39456c0599891c535f024ff0b64cec5eb8c8a56d5d91f83d96f300d5009c8098a7f73cdcb62ccf778fbc0a7feb0b96b
@@ -14,15 +14,13 @@ module Popro
14
14
  Progress.new(**options, &block)
15
15
  end
16
16
 
17
- def self.each(obj, _total = nil, **options, &block)
17
+ def self.each(obj, total = nil, **options, &block)
18
+ options[:step] = 0 unless options.key? :step
18
19
  new(0, **options).each(obj, total, &block).done
19
20
  end
20
21
 
21
- def self.each0(obj, **options, &block)
22
- raise ConfigError, 'using :step is not supported in each0' if options.key?(:step)
23
-
24
- options[:step] = 0
25
- each(obj, 0, **options, &block)
22
+ def self.each_will(obj, titler, total = nil, **options, &block)
23
+ new(0, **options).each_will(obj, titler, total, &block).done
26
24
  end
27
25
 
28
26
  def self.command_line(*_args)
@@ -3,7 +3,7 @@
3
3
  module Popro
4
4
  # the progress context passed as first argument to blocks (or named argument for `Progress#each` and `Popro.each`)
5
5
 
6
- WILL_CHECK_MARKS ||= '☐☑'
6
+ WILL_CHECK_MARKS ||= ''
7
7
 
8
8
  class Context
9
9
  def initialize(progress:, info:, indicator:, step: 1)
@@ -14,25 +14,17 @@ module Popro
14
14
  end
15
15
 
16
16
  def each(obj, total = nil, &block)
17
- total = obj.size if total.nil?
18
- @info.total += total if total.positive?
19
- block = proc { |d| d } unless block_given?
20
-
21
- obj.each do |*args|
22
- did block.call(*args, progress: self)
17
+ _each(obj, total) do |*args|
18
+ did block.call(*args, progress: @info)
23
19
  end
24
-
25
- self
26
20
  end
27
21
 
28
- def each0(obj, &block)
29
- each(obj, 0, &block)
30
- end
31
-
32
- def each_will(obj, titler, total = nil)
33
- each(obj, total) do |*args, **kwargs|
34
- kwargs[:progress].will titler.call(*args) do
35
- yield(*args, **kwargs)
22
+ def each_will(obj, titler, total = nil, &block)
23
+ _each(obj, total) do |*args|
24
+ title = titler.call(*args)
25
+ will(title) do
26
+ block.call(*args, progress: @info)
27
+ nil
36
28
  end
37
29
  end
38
30
  end
@@ -59,25 +51,25 @@ module Popro
59
51
  block
60
52
  end
61
53
 
62
- def did(yielded = nil, amount = 1)
54
+ def did(yielded = nil, amount = nil)
63
55
  @info.start unless @info.running?
64
- inc amount, yielded
56
+ amount = @step if amount.nil?
57
+ raise TypeError('amount: expected an integer') unless amount.is_a? Integer
58
+
59
+ @info.current += amount unless amount.zero?
60
+ @indicator.call(@info, yielded)
65
61
 
66
62
  self
67
63
  end
68
64
 
69
- def will(title = nil, use_block_result_as_title = nil, step = nil)
70
- @info.start unless @info.running?
71
- inc 0, "#{WILL_CHECK_MARKS[0]} #{title}"
65
+ def will(title = nil, step = nil, &block)
66
+ did "#{WILL_CHECK_MARKS[0]} #{title}", 0
72
67
 
73
68
  return self unless block_given?
74
69
 
75
- step = @step if step.nil?
76
- yielded = yield @context
77
- yielded = "#{WILL_CHECK_MARKS[1]} #{title}" unless title.nil? || use_block_result_as_title
78
-
79
- # no need to communicate to Indicator if we are not advancing (avoid double calls)
80
- did yielded, step unless step.zero?
70
+ block.call
71
+ yielded = "#{WILL_CHECK_MARKS[1]} #{title}"
72
+ did(yielded, step || @step)
81
73
  yielded
82
74
  end
83
75
 
@@ -87,11 +79,18 @@ module Popro
87
79
 
88
80
  private
89
81
 
90
- def inc(amount, yielded = nil)
91
- raise TypeError('expected an integer') unless amount.is_a? Integer
82
+ def _each(obj, total = nil, &block)
83
+ total = obj.size if total.nil?
84
+ raise TypeError('total: expected an integer') unless total.is_a?(Integer) || total.nil?
92
85
 
93
- @info.current += amount unless amount.zero?
94
- @indicator.call(@info, yielded)
86
+ @info.total += total if total.positive?
87
+ # block = proc { |d| d } unless block_given?
88
+
89
+ obj.each do |*args, **kwargs|
90
+ block.call(*args, **kwargs)
91
+ end
92
+
93
+ self
95
94
  end
96
95
  end
97
96
  end
@@ -57,7 +57,6 @@ module Popro
57
57
 
58
58
  def to_h
59
59
  {
60
- started: @started,
61
60
  pct: pct,
62
61
  pct_formatted: pct_formatted,
63
62
  current: @current,
@@ -30,7 +30,7 @@ module Popro
30
30
 
31
31
  def register_aliases
32
32
  class << self
33
- %i[each each0 each_will to_proc did will formatter start done].each do |method_name|
33
+ %i[each each_will to_proc did will formatter start done].each do |method_name|
34
34
  define_method method_name do |*args, &block|
35
35
  @context.public_send(method_name, *args, &block)
36
36
  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.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MikeSmithEU