output_mode 1.5.0 → 1.5.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: 33db72e9e5872a974df80e11a0d4bae3735c13d49d3be4d4ab1366b7e461551f
4
- data.tar.gz: f1ac7923d6cb9beda1f3af36ebaa41b84cdb6567d5fb71db4f2d1a2503ee731b
3
+ metadata.gz: f4492bb6d42dfd55f9f83ba7a3fd7fa9b21a2712760272cbd1d3500dafc11dd4
4
+ data.tar.gz: 71068e9161e4219ab85508a6692046f2de51d19a83c685b40fa9212ac0d40c46
5
5
  SHA512:
6
- metadata.gz: f12f87485cdad45ceb4fba9b9b26c405366009b1ad39e87c223fc246424bd0501421a75570caf48c351523d55483f4ea1d705659a3e6185ae8213c6147d9ad96
7
- data.tar.gz: cafd82a58648d5e4900c91d242a1128b2b1c5d1123716385160801a3d85959324df691ecd7c8443e038612e4c2b2afb221745da598483e239a15a7ef9a701c0a
6
+ metadata.gz: 05d68669d5abbb2ac911531c8709d4d44898fcaae4fced442d5bf8ffc2d935d5c2ef8319bc2b28cb5e33fb7b033b236c57992d449b1de4c69f667b3248c8d08f
7
+ data.tar.gz: c6aae6fc8496bb491b4213173c4fc7bd57499efd9f2ec1e4367f3ec46b849c6be41453f17065c44a0b687aa40c1b6d1c677fe9578ad3dea11f8a92e31722f78a
@@ -56,13 +56,23 @@ module OutputMode
56
56
  @callables.each(&block)
57
57
  end
58
58
 
59
- def pad_each(key = :header)
60
- max_length = self.map { |c| c.config[key].to_s.length }
61
- .max
59
+ def pad_each(key = :header, *ctx)
60
+ fields = self.map do |callables|
61
+ field = callables.config[key]
62
+ if field.respond_to?(:call) && ctx.empty?
63
+ raise Error, 'Can not pad dynamic fields without a context'
64
+ elsif field.respond_to?(:call)
65
+ field.call(*ctx).to_s
66
+ else
67
+ field.to_s
68
+ end
69
+ end
62
70
 
63
- pads = self.map do |callable|
64
- length = max_length - callable.config[key].to_s.length
65
- [callable, { padding: ' ' * length }]
71
+ max_length = fields.map(&:length).max
72
+ pads = self.each_with_index.map do |callable, idx|
73
+ field = fields[idx]
74
+ length = max_length - field.length
75
+ [callable, { padding: ' ' * length, field: field }]
66
76
  end
67
77
 
68
78
  if block_given?
@@ -25,5 +25,5 @@
25
25
  #==============================================================================
26
26
 
27
27
  module OutputMode
28
- VERSION = "1.5.0"
28
+ VERSION = "1.5.1"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: output_mode
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - William McCumsite
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-10 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-table