infobar 0.13.1 → 0.13.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce90bf89a05aa85dd2dafe44ce71c68719984a4553195f7c5ee3ea85a557e544
4
- data.tar.gz: 2843fc691f0d520c3b1af317ec4faa6605cb40062abe384623f7c9fcc2ccf77e
3
+ metadata.gz: d40d5b452af90e9dc3a001fbed6b3a99592c9957f961ff5e80023bad450470fd
4
+ data.tar.gz: e09df34cc5ec2d154ad72e9b93430086b33f11c8fce42990fcc205d3923244c8
5
5
  SHA512:
6
- metadata.gz: b46cf5616ff55923b82a17d116729121b893be14446549878e911693986e9cff250dfeccfde5f0fd980d8775ec9b4c096d4117fe78c63556ad6560b8452c3ee4
7
- data.tar.gz: a473c4788dd8cb8f09801537b18b8732fec231a62138a7a5b2bd75623d5d58186a7e7cafe27a59713ec5b272c8b13fbeea66d8768ddb31b20b8da178e06f757f
6
+ metadata.gz: 61dccf5182cc602737ca95da8f583adbea6cabc7b33e5ae7a0f205ca3eb7535f51e08139293be6d30b2289042017ee4dd38f5f027c95952e422f1724bb3efcea
7
+ data.tar.gz: c7aca2ac7d23e230b56cdd464154187795ae83e53babdcadf762fe9560bfbe950ddaec4e4917bf728006269c5b6470ab4e47ab1d2209ada2e79ca1ff390cc6fb
@@ -0,0 +1,51 @@
1
+ # Simple workflow for deploying static content to GitHub Pages
2
+ name: Deploy static content to Pages
3
+
4
+ on:
5
+ # Runs on pushes targeting the default branch
6
+ push:
7
+ branches: [ "master" ]
8
+
9
+ # Allows you to run this workflow manually from the Actions tab
10
+ workflow_dispatch:
11
+
12
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13
+ permissions:
14
+ contents: read
15
+ pages: write
16
+ id-token: write
17
+
18
+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19
+ # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20
+ concurrency:
21
+ group: "pages"
22
+ cancel-in-progress: false
23
+
24
+ jobs:
25
+ # Single deploy job since we're just deploying
26
+ deploy:
27
+ environment:
28
+ name: github-pages
29
+ url: ${{ steps.deployment.outputs.page_url }}
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - name: Checkout
33
+ uses: actions/checkout@v6
34
+ - name: Setup Pages
35
+ uses: actions/configure-pages@v6
36
+ - name: Setup Ruby
37
+ uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: '4.0'
40
+ - name: Generate Documentation
41
+ run: |
42
+ gem install gem_hadar
43
+ bundle install
44
+ rake doc
45
+ - name: Upload artifact
46
+ uses: actions/upload-pages-artifact@v5
47
+ with:
48
+ path: 'doc'
49
+ - name: Deploy to GitHub Pages
50
+ id: deployment
51
+ uses: actions/deploy-pages@v5
data/CHANGES.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-11-13 v0.13.2
4
+
5
+ ### Improvements
6
+
7
+ - Added a GitHub Actions workflow (`.github/workflows/static.yml`) to generate
8
+ YARD documentation and deploy it to GitHub Pages on pushes to `master`.
9
+ - Added a `Documentation` section to `README.md` linking to the hosted API
10
+ documentation.
11
+ - Added comprehensive YARD documentation to all files under `lib/infobar/` and
12
+ `lib/infobar.rb`, including class descriptions, method signatures, parameter
13
+ details, and return types.
14
+ - Replaced the BSD-specific `getconf _NPROCESSORS_ONLN` command with the
15
+ portable `nproc` command in the CI build script.
16
+ - Added status feedback messages (using emoji) to the CI `after` hook to
17
+ indicate test success or failure.
18
+ - Added `doc/` to `.gitignore` and the `Rakefile` ignore lists to exclude
19
+ generated documentation from version control and gem packages.
20
+
21
+ ### Build & CI
22
+
23
+ - Updated the `rubygems_version` in `infobar.gemspec` to **4.0.24**.
24
+ - Raised the `gem_hadar` development dependency requirement to **>= 2.21.0**.
25
+ - Added `git config --global --add safe.directory /work` to the CI build script
26
+ to prevent Git ownership safety warnings during test execution.
27
+ - Registered the new `static.yml` workflow in the `Rakefile` via
28
+ `github_workflows`.
29
+ - Added `.github/workflows/static.yml` to the list of distributed gem files in
30
+ `infobar.gemspec`.
31
+
3
32
  ## 2026-01-29 v0.13.1
4
33
 
5
34
  - Added `newline` method call in `ensure` block of `Infobar` class to ensure
data/README.md CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  Display progress of computations and additional information to the terminal.
6
6
 
7
+ ## Documentation
8
+
9
+ Complete API documentation is available at: [GitHub.io](https://flori.github.io/infobar/)
10
+
7
11
  ## Installation
8
12
 
9
13
  # gem install infobar
data/Rakefile CHANGED
@@ -13,9 +13,9 @@ GemHadar do
13
13
  test_dir 'spec'
14
14
  ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
15
15
  '.AppleDouble', 'tags', '.DS_Store', 'errors.lst', '.tool-versions',
16
- '.bundle', '.yardoc'
16
+ '.bundle', '.yardoc', 'doc'
17
17
  package_ignore '.utilsrc', '.all_images.yml', 'VERSION', '.rspec',
18
- '.gitignore', 'TODO.md'
18
+ '.gitignore', 'TODO.md', 'doc'
19
19
 
20
20
  readme 'README.md'
21
21
  title "#{name.camelize}"
@@ -24,6 +24,10 @@ GemHadar do
24
24
  filename 'CHANGES.md'
25
25
  end
26
26
 
27
+ github_workflows(
28
+ 'static.yml' => {}
29
+ )
30
+
27
31
  required_ruby_version '>= 3.1'
28
32
  dependency 'tins', '~> 1', '>= 1.28.0'
29
33
  dependency 'term-ansicolor', '~> 1.11'
data/infobar.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: infobar 0.13.1 ruby lib
2
+ # stub: infobar 0.13.2 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "infobar".freeze
6
- s.version = "0.13.1".freeze
6
+ s.version = "0.13.2".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -12,17 +12,17 @@ Gem::Specification.new do |s|
12
12
  s.description = "This gem displays progress of computations and additional information to the terminal.".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.extra_rdoc_files = ["README.md".freeze, "lib/infobar.rb".freeze, "lib/infobar/counter.rb".freeze, "lib/infobar/display.rb".freeze, "lib/infobar/duration.rb".freeze, "lib/infobar/fancy_interface.rb".freeze, "lib/infobar/fifo.rb".freeze, "lib/infobar/frequency.rb".freeze, "lib/infobar/input_output.rb".freeze, "lib/infobar/message.rb".freeze, "lib/infobar/number.rb".freeze, "lib/infobar/rate.rb".freeze, "lib/infobar/spinner.rb".freeze, "lib/infobar/timer.rb".freeze, "lib/infobar/trend.rb".freeze, "lib/infobar/version.rb".freeze]
15
- s.files = ["CHANGES.md".freeze, "COPYING".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "infobar.gemspec".freeze, "lib/infobar.rb".freeze, "lib/infobar/counter.rb".freeze, "lib/infobar/display.rb".freeze, "lib/infobar/duration.rb".freeze, "lib/infobar/fancy_interface.rb".freeze, "lib/infobar/fifo.rb".freeze, "lib/infobar/frequency.rb".freeze, "lib/infobar/input_output.rb".freeze, "lib/infobar/message.rb".freeze, "lib/infobar/number.rb".freeze, "lib/infobar/rate.rb".freeze, "lib/infobar/spinner.rb".freeze, "lib/infobar/timer.rb".freeze, "lib/infobar/trend.rb".freeze, "lib/infobar/version.rb".freeze, "spec/config/infobar.yml".freeze, "spec/infobar/config_spec.rb".freeze, "spec/infobar/counter_spec.rb".freeze, "spec/infobar/display_spec.rb".freeze, "spec/infobar/duration_spec.rb".freeze, "spec/infobar/fifo_spec.rb".freeze, "spec/infobar/frequency_spec.rb".freeze, "spec/infobar/input_output_spec.rb".freeze, "spec/infobar/message_spec.rb".freeze, "spec/infobar/number_spec.rb".freeze, "spec/infobar/rate_spec.rb".freeze, "spec/infobar/spinner_spec.rb".freeze, "spec/infobar/timer_spec.rb".freeze, "spec/infobar/trend_spec.rb".freeze, "spec/infobar_spec.rb".freeze, "spec/spec_helper.rb".freeze]
15
+ s.files = [".github/workflows/static.yml".freeze, "CHANGES.md".freeze, "COPYING".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "infobar.gemspec".freeze, "lib/infobar.rb".freeze, "lib/infobar/counter.rb".freeze, "lib/infobar/display.rb".freeze, "lib/infobar/duration.rb".freeze, "lib/infobar/fancy_interface.rb".freeze, "lib/infobar/fifo.rb".freeze, "lib/infobar/frequency.rb".freeze, "lib/infobar/input_output.rb".freeze, "lib/infobar/message.rb".freeze, "lib/infobar/number.rb".freeze, "lib/infobar/rate.rb".freeze, "lib/infobar/spinner.rb".freeze, "lib/infobar/timer.rb".freeze, "lib/infobar/trend.rb".freeze, "lib/infobar/version.rb".freeze, "spec/config/infobar.yml".freeze, "spec/infobar/config_spec.rb".freeze, "spec/infobar/counter_spec.rb".freeze, "spec/infobar/display_spec.rb".freeze, "spec/infobar/duration_spec.rb".freeze, "spec/infobar/fifo_spec.rb".freeze, "spec/infobar/frequency_spec.rb".freeze, "spec/infobar/input_output_spec.rb".freeze, "spec/infobar/message_spec.rb".freeze, "spec/infobar/number_spec.rb".freeze, "spec/infobar/rate_spec.rb".freeze, "spec/infobar/spinner_spec.rb".freeze, "spec/infobar/timer_spec.rb".freeze, "spec/infobar/trend_spec.rb".freeze, "spec/infobar_spec.rb".freeze, "spec/spec_helper.rb".freeze]
16
16
  s.homepage = "https://github.com/flori/infobar".freeze
17
17
  s.rdoc_options = ["--title".freeze, "Infobar".freeze, "--main".freeze, "README.md".freeze]
18
18
  s.required_ruby_version = Gem::Requirement.new(">= 3.1".freeze)
19
- s.rubygems_version = "4.0.3".freeze
19
+ s.rubygems_version = "4.0.24".freeze
20
20
  s.summary = "Gem to display information about computations.".freeze
21
21
  s.test_files = ["spec/infobar/config_spec.rb".freeze, "spec/infobar/counter_spec.rb".freeze, "spec/infobar/display_spec.rb".freeze, "spec/infobar/duration_spec.rb".freeze, "spec/infobar/fifo_spec.rb".freeze, "spec/infobar/frequency_spec.rb".freeze, "spec/infobar/input_output_spec.rb".freeze, "spec/infobar/message_spec.rb".freeze, "spec/infobar/number_spec.rb".freeze, "spec/infobar/rate_spec.rb".freeze, "spec/infobar/spinner_spec.rb".freeze, "spec/infobar/timer_spec.rb".freeze, "spec/infobar/trend_spec.rb".freeze, "spec/infobar_spec.rb".freeze, "spec/spec_helper.rb".freeze]
22
22
 
23
23
  s.specification_version = 4
24
24
 
25
- s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.17.0".freeze])
25
+ s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.21.0".freeze])
26
26
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
27
27
  s.add_development_dependency(%q<rspec>.freeze, [">= 0".freeze])
28
28
  s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
@@ -1,20 +1,42 @@
1
1
  require 'infobar/timer'
2
2
 
3
+ # A progress counter that tracks items, rates, and elapsed time.
4
+ #
5
+ # Internally uses an +Infobar::Timer+ for Welford-style online
6
+ # mean computation and a +FIFO+ for rate trending.
7
+ #
8
+ # @example Create and advance a counter
9
+ # counter = Infobar::Counter.new
10
+ # counter.reset(total: 10)
11
+ # counter.progress(by: 1)
3
12
  class Infobar::Counter
4
13
  class << self
5
14
  prepend Tins::Delegate
6
15
  end
7
16
 
17
+ # Creates a new Counter in a clean, zeroed state.
8
18
  def initialize
9
19
  reset
10
20
  end
11
21
 
22
+ # @!attribute [r] current
23
+ # @return [Integer] the number of items processed so far
12
24
  attr_reader :current
13
25
 
26
+ # @!attribute [r] total
27
+ # @return [Integer] the total number of items expected
14
28
  attr_reader :total
15
29
 
30
+ # @!attribute [r] as
31
+ # @return [Hash{Object => Integer}] per-category counts keyed
32
+ # by the +as:+ label (+nil+ is the default bucket)
16
33
  attr_reader :as
17
34
 
35
+ # Resets all internal state.
36
+ #
37
+ # @param total [Integer] total number of items
38
+ # @param current [Integer] starting item count
39
+ # @return [Infobar::Counter] self
18
40
  def reset(total: 0, current: 0)
19
41
  @current = current
20
42
  @as = Hash.new(0).update(nil => current)
@@ -31,19 +53,35 @@ class Infobar::Counter
31
53
 
32
54
  delegate :average_time, to: :@timer
33
55
 
56
+ # Whether the counter has been started.
57
+ #
58
+ # @return [Time, nil] the start time, or +nil+ if not started
34
59
  def started?
35
60
  @start
36
61
  end
37
62
 
63
+ # Whether the counter has been explicitly finished.
64
+ #
65
+ # @return [Time, false] the finish time, or +false+
38
66
  def finished?
39
67
  @finished
40
68
  end
41
69
 
70
+ # Marks the counter as finished at the current time.
71
+ #
72
+ # @return [Infobar::Counter] self
42
73
  def finish
43
74
  @finished = Time.now
44
75
  self
45
76
  end
46
77
 
78
+ # Advances the counter by the given amount.
79
+ #
80
+ # No-ops if the counter is finished or +by+ is less than 1.
81
+ #
82
+ # @param by [Integer] number of items to advance
83
+ # @param as [Object, nil] category label for per-category tracking
84
+ # @return [Infobar::Counter] self
47
85
  def progress(by: 1, as: nil)
48
86
  if !finished? && by >= 1
49
87
  now = Time.now
@@ -55,18 +93,30 @@ class Infobar::Counter
55
93
  self
56
94
  end
57
95
 
96
+ # Whether all items have been processed.
97
+ #
98
+ # @return [Boolean]
58
99
  def done?
59
100
  @current >= @total
60
101
  end
61
102
 
103
+ # Number of items remaining.
104
+ #
105
+ # @return [Integer] always >= 0
62
106
  def to_go
63
107
  [ total - current, 0 ].max
64
108
  end
65
109
 
110
+ # Whether there are items remaining.
111
+ #
112
+ # @return [Integer, nil] the remaining count or +nil+ if zero
66
113
  def to_go?
67
114
  to_go.nonzero?
68
115
  end
69
116
 
117
+ # Estimated seconds until completion.
118
+ #
119
+ # @return [Float] 0.0 if finished
70
120
  def time_remaining
71
121
  if @finished
72
122
  0.0
@@ -75,6 +125,9 @@ class Infobar::Counter
75
125
  end
76
126
  end
77
127
 
128
+ # Estimated time of completion.
129
+ #
130
+ # @return [Time] the finish time or projected finish
78
131
  def eta
79
132
  if @finished
80
133
  @finished
@@ -83,6 +136,9 @@ class Infobar::Counter
83
136
  end
84
137
  end
85
138
 
139
+ # Seconds elapsed since the counter started.
140
+ #
141
+ # @return [Float] 0.0 if not started
86
142
  def time_elapsed
87
143
  case
88
144
  when @finished && @start
@@ -94,10 +150,16 @@ class Infobar::Counter
94
150
  end
95
151
  end
96
152
 
153
+ # Total projected duration (elapsed + remaining).
154
+ #
155
+ # @return [Float]
97
156
  def total_time
98
157
  time_elapsed + time_remaining
99
158
  end
100
159
 
160
+ # Progress as a float between 0 and 1.
161
+ #
162
+ # @return [Float] 0.0 when total is zero
101
163
  def progressed
102
164
  if @total.zero?
103
165
  0.0
@@ -106,6 +168,9 @@ class Infobar::Counter
106
168
  end
107
169
  end
108
170
 
171
+ # Multi-line summary of per-category counts.
172
+ #
173
+ # @return [String] one line per category, e.g. +"default: 42"+
109
174
  def to_s
110
175
  n = -> k { k.nil? ? 'default' : k.to_s }
111
176
  width = -@as.keys.map(&n).max_by(&:size).to_i
@@ -2,12 +2,24 @@ require 'term/ansicolor'
2
2
  require 'stringio'
3
3
  require 'infobar/frequency'
4
4
 
5
+ # Terminal renderer for the progress bar.
6
+ #
7
+ # Draws a single-line bar with ANSI colors, respecting a
8
+ # configurable update +Frequency+. Supports per-category styling
9
+ # via +as_styles+ and a global +style+ hash.
10
+ #
11
+ # @example Create a display and update it
12
+ # display = Infobar::Display.new
13
+ # display.update(message: 'Working...', counter: counter)
5
14
  class Infobar::Display
6
15
  class << self
7
16
  prepend Tins::Delegate
8
17
  end
9
18
  include Term::ANSIColor
10
19
 
20
+ # Returns the default style hash for the progress bar.
21
+ #
22
+ # @return [Hash{Symbol => Object}] fill characters and ANSI colors
11
23
  def self.default_style
12
24
  {
13
25
  done_fill: ?░,
@@ -19,6 +31,7 @@ class Infobar::Display
19
31
  }
20
32
  end
21
33
 
34
+ # Creates a Display writing to +$stdout+ / reading from +$stdin+.
22
35
  def initialize
23
36
  self.output = $stdout
24
37
  self.input = $stdin
@@ -27,23 +40,39 @@ class Infobar::Display
27
40
  @style = self.class.default_style.dup
28
41
  end
29
42
 
43
+ # Sets the update frequency threshold.
44
+ #
45
+ # @param duration [Numeric] minimum seconds between updates
30
46
  def frequency=(duration)
31
47
  @frequency = Infobar::Frequency.new(duration)
32
48
  end
33
49
 
50
+ # @!attribute [r] frequency
51
+ # @return [Infobar::Frequency] the rate-limiting gate
34
52
  attr_reader :frequency
35
53
 
54
+ # @!attribute [rw] show
55
+ # @return [Boolean] whether output is rendered or discarded
36
56
  attr_accessor :show
37
57
 
58
+ # Whether the display is currently visible.
59
+ #
60
+ # @return [Boolean]
38
61
  def show?
39
62
  @show
40
63
  end
41
64
 
65
+ # Sets the output IO, enabling +sync+= if supported.
66
+ #
67
+ # @param io [IO] the destination for bar output
42
68
  def output=(io)
43
69
  @output = io
44
70
  @output.ask_and_send(:respond_to?, :sync=, true)
45
71
  end
46
72
 
73
+ # Returns the active output IO, or +NULL+ when hidden.
74
+ #
75
+ # @return [IO]
47
76
  def output
48
77
  if show?
49
78
  @output
@@ -52,8 +81,13 @@ class Infobar::Display
52
81
  end
53
82
  end
54
83
 
84
+ # @!attribute [w] input
85
+ # Sets the source IO for user input.
55
86
  attr_writer :input
56
87
 
88
+ # Returns the active input IO, or +NULL+ when hidden.
89
+ #
90
+ # @return [IO]
57
91
  def input
58
92
  if show?
59
93
  @input
@@ -62,22 +96,41 @@ class Infobar::Display
62
96
  end
63
97
  end
64
98
 
99
+ # @!attribute [r] style
100
+ # @return [Hash{Symbol => Object}] the current global style
65
101
  attr_reader :style
66
102
 
103
+ # Merges new style options into the current style.
104
+ #
105
+ # @param new_style [Hash{Symbol => Object}] overrides to apply
67
106
  def style=(new_style)
68
107
  @style.update(**new_style)
69
108
  end
70
109
 
110
+ # Per-category style overrides. Lazily initialized.
111
+ #
112
+ # @return [Hash{Symbol => Hash}] category-specific styles
71
113
  def as_styles
72
114
  defined? @as_styles or self.as_styles = {}
73
115
  @as_styles
74
116
  end
75
117
 
118
+ # Sets per-category styles with a default proc falling back
119
+ # to the global +done_*+ entries.
120
+ #
121
+ # @param styles [Hash] category name to style hash mapping
76
122
  def as_styles=(styles)
77
123
  @as_styles = styles.to_h.symbolize_keys_recursive
78
124
  @as_styles.default_proc = proc { style.subhash(/\Adone_/) }
79
125
  end
80
126
 
127
+ # Renders the progress bar if the frequency gate allows.
128
+ #
129
+ # @param message [Infobar::Message, String, Hash, nil] the text
130
+ # to display alongside the bar
131
+ # @param counter [Infobar::Counter, nil] the counter driving the bar
132
+ # @param force [Boolean] bypass the frequency gate
133
+ # @param options [Hash] additional style overrides for this update
81
134
  def update(message: nil, counter: nil, force: false, **options)
82
135
  force and @frequency.reset
83
136
  @frequency.call do
@@ -125,12 +178,19 @@ class Infobar::Display
125
178
 
126
179
  delegate :called, to: :frequency, as: :updates
127
180
 
181
+ # Resets the display to defaults, optionally clearing the line.
182
+ #
183
+ # @param clear [Boolean] whether to blank the current line
184
+ # @return [Infobar::Display] self
128
185
  def reset(clear: true)
129
186
  clear && self.clear
130
187
  self.style = self.class.default_style
131
188
  self
132
189
  end
133
190
 
191
+ # Clears the current bar line and resets the frequency gate.
192
+ #
193
+ # @return [Infobar::Display] self
134
194
  def clear
135
195
  carriage_return
136
196
  output << ' ' * columns
@@ -139,11 +199,17 @@ class Infobar::Display
139
199
  self
140
200
  end
141
201
 
202
+ # Emits a carriage return to the output.
203
+ #
204
+ # @return [Infobar::Display] self
142
205
  def carriage_return
143
206
  output << ?\r
144
207
  self
145
208
  end
146
209
 
210
+ # Emits a newline to the output.
211
+ #
212
+ # @return [Infobar::Display] self
147
213
  def newline
148
214
  output << $/
149
215
  self
@@ -151,10 +217,17 @@ class Infobar::Display
151
217
 
152
218
  private
153
219
 
220
+ # The Unicode Object Replacement Character used as a
221
+ # temporary fill during bar layout.
222
+ #
223
+ # @return [String]
154
224
  def replace_character
155
225
  "\uFFFC"
156
226
  end
157
227
 
228
+ # Returns the current terminal width in columns.
229
+ #
230
+ # @return [Integer]
158
231
  def columns
159
232
  Tins::Terminal.columns
160
233
  end
@@ -1,4 +1,17 @@
1
+ # A formatted duration string backed by +Tins::Duration.
2
+ #
3
+ # @example Create a default-formatted duration
4
+ # Infobar::Duration.new(42.5).to_s
5
+ #
6
+ # @example Custom format
7
+ # Infobar::Duration.new(42.5, format: '%m:%s').to_s
8
+ # # => "00:42"
1
9
  class Infobar::Duration
10
+ # Initializes a new Duration.
11
+ #
12
+ # @param value [Numeric] the number of seconds
13
+ # @param format [String, nil] a +Tins::Duration#+format string,
14
+ # e.g. +'%D'+, +'%m:%s'+, or +nil+ for the default
2
15
  def initialize(value, format: nil)
3
16
  duration = Tins::Duration.new(value)
4
17
  @string =
@@ -9,6 +22,9 @@ class Infobar::Duration
9
22
  end.to_s
10
23
  end
11
24
 
25
+ # Returns the pre-formatted duration string.
26
+ #
27
+ # @return [String]
12
28
  def to_s
13
29
  @string
14
30
  end
@@ -1,32 +1,61 @@
1
+ # A syntactic sugar module that lets you treat an +Infobar+ instance
2
+ # like a counter with familiar operators.
3
+ #
4
+ # @example Basic usage
5
+ # Infobar(total: 10)
6
+ # +infobar
7
+ # infobar << item
8
+ # infobar.add(1, 2, 3)
1
9
  module Infobar::FancyInterface
10
+ # Resets the counter and display.
11
+ # @return [Infobar] the infobar instance
2
12
  def ~
3
13
  reset
4
14
  end
5
15
 
16
+ # Advances progress by 1 under the +true+ key.
17
+ # @return [Infobar] the infobar instance
6
18
  def +@
7
19
  progress by: 1, as: true
8
20
  end
9
21
 
22
+ # Advances progress by 1 under the +false+ key.
23
+ # @return [Infobar] the infobar instance
10
24
  def -@
11
25
  progress by: 1, as: false
12
26
  end
13
27
 
28
+ # Advances progress by +by+ under the +true+ key.
29
+ # @param by [Integer] the number of items to advance
30
+ # @return [Infobar] the infobar instance
14
31
  def +(by)
15
32
  progress by: by, as: true
16
33
  end
17
34
 
35
+ # Advances progress by +by+ under the +false+ key.
36
+ # @param by [Integer] the number of items to advance
37
+ # @return [Infobar] the infobar instance
18
38
  def -(by)
19
39
  progress by: by, as: false
20
40
  end
21
41
 
42
+ # Enables +infobar + other+ and +other + infobar+ syntax.
43
+ # @param other [Object] the other operand
44
+ # @return [Array] a two-element array for coercion
22
45
  def coerce(other)
23
46
  return self, other
24
47
  end
25
48
 
49
+ # Advances progress by 1 (shorthand for +progress+).
50
+ # @param item [Object] the item being processed (unused)
51
+ # @return [Infobar] the infobar instance
26
52
  def <<(item)
27
53
  progress by: 1
28
54
  end
29
55
 
56
+ # Advances progress by the number of items given.
57
+ # @param items [Array] the items being processed
58
+ # @return [Infobar] the infobar instance
30
59
  def add(*items)
31
60
  progress by: items.size
32
61
  end
data/lib/infobar/fifo.rb CHANGED
@@ -1,15 +1,37 @@
1
+ # A fixed-capacity first-in-first-out buffer.
2
+ #
3
+ # Includes +Enumerable+ for iteration. When the buffer is full, the
4
+ # oldest element is evicted on push.
5
+ #
6
+ # @example Create and fill a FIFO
7
+ # fifo = Infobar::FIFO.new(3)
8
+ # fifo << 1 # => 1
9
+ # fifo << 2 # => 2
10
+ # fifo << 3 # => 3
11
+ # fifo << 4 # => 4 (1 is evicted)
1
12
  class Infobar::FIFO
2
13
  include Enumerable
3
14
 
15
+ # Initializes a new FIFO with the given maximum capacity.
16
+ #
17
+ # @param n [Integer] the maximum number of elements to retain
4
18
  def initialize(n)
5
19
  @n = n
6
20
  clear
7
21
  end
8
22
 
23
+ # Returns the maximum capacity of the buffer.
24
+ #
25
+ # @return [Integer]
9
26
  def max_size
10
27
  @n
11
28
  end
12
29
 
30
+ # Pushes a value into the buffer, evicting the oldest element
31
+ # if the buffer is at capacity.
32
+ #
33
+ # @param value [Object] the element to push
34
+ # @return [Infobar::FIFO] self for chaining
13
35
  def <<(value)
14
36
  @i += 1
15
37
  if @i > @n
@@ -20,21 +42,30 @@ class Infobar::FIFO
20
42
  self
21
43
  end
22
44
 
45
+ # Iterates over all elements currently in the buffer.
46
+ #
47
+ # @yield [element] yields each stored element
48
+ # @return [Infobar::FIFO] self
23
49
  def each(&block)
24
50
  @values.each(&block)
25
51
  self
26
52
  end
27
53
 
54
+ # Whether the buffer is empty.
55
+ #
56
+ # @return [Boolean]
28
57
  def empty?
29
58
  @i.zero?
30
59
  end
31
60
 
32
61
  alias size count
33
62
 
63
+ # Clears all elements from the buffer.
64
+ #
65
+ # @return [Infobar::FIFO] self
34
66
  def clear
35
67
  @i = 0
36
68
  @values = []
37
69
  self
38
70
  end
39
71
  end
40
-