Class: TTY::ProgressBar::Formatter
- Inherits:
-
Module
- Object
- Module
- TTY::ProgressBar::Formatter
- Defined in:
- lib/tty/progressbar/formatter.rb
Class Method Summary collapse
-
.[](token_match) ⇒ Object
A helper for declaring a matching token pattern.
Instance Method Summary collapse
-
#initialize(token_match) ⇒ Formatter
constructor
Initialize this module with token matching pattern.
Constructor Details
#initialize(token_match) ⇒ Formatter
Initialize this module with token matching pattern
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tty/progressbar/formatter.rb', line 19 def initialize(token_match) pattern = token_match module_eval do define_method(:initialize) do |progress| @progress = progress end define_method(:matcher) { pattern } define_method(:progress) { @progress } # Determines whether this formatter is applied or not. # # @param [Object] value # # @return [Boolean] # # @api private define_method(:matches?) do |value| !!(value.to_s =~ pattern) end end end |
Class Method Details
.[](token_match) ⇒ Object
A helper for declaring a matching token pattern
9 10 11 |
# File 'lib/tty/progressbar/formatter.rb', line 9 def self.[](token_match) new(token_match) end |