Class: Pdfh::Console
- Inherits:
-
Object
- Object
- Pdfh::Console
- Defined in:
- lib/pdfh/utils/console.rb
Overview
All console output formats
Instance Method Summary collapse
- #debug(message = nil) ⇒ void
- #error_print(message, exit_app: true) ⇒ void
-
#headline(title) ⇒ void
Prints visual separator in shell for easier reading for humans ——— Title ——————————————— …
- #ident_print(field, value, color: :green, width: 3) ⇒ void
- #info(message) ⇒ void
- #initialize(verbose) ⇒ self constructor
-
#print_options(options) ⇒ void
Show options used to run the current sync job.
- #warn_print(message) ⇒ void
Constructor Details
#initialize(verbose) ⇒ self
7 8 9 |
# File 'lib/pdfh/utils/console.rb', line 7 def initialize(verbose) @verbose = verbose end |
Instance Method Details
#debug(message = nil) ⇒ void
This method returns an undefined value.
12 13 14 15 16 |
# File 'lib/pdfh/utils/console.rb', line 12 def debug( = nil) msg = .to_s msg = msg.colorize(:cyan) unless msg.colorized? output(msg) if verbose? end |
#error_print(message, exit_app: true) ⇒ void
This method returns an undefined value.
39 40 41 42 |
# File 'lib/pdfh/utils/console.rb', line 39 def error_print(, exit_app: true) output "Error, #{}".colorize(:red) exit 1 if exit_app end |
#headline(title) ⇒ void
This method returns an undefined value.
Prints visual separator in shell for easier reading for humans ——— Title ——————————————— … ——————
28 29 30 31 32 33 34 |
# File 'lib/pdfh/utils/console.rb', line 28 def headline(title) _, cols = console_size line_length = cols - (title.size + 5) left = ("—" * 3).to_s.red right = ("—" * line_length).to_s.red output "\n#{left} #{title.colorize(color: :blue, mode: :bold)} #{right}" end |
#ident_print(field, value, color: :green, width: 3) ⇒ void
This method returns an undefined value.
54 55 56 57 58 |
# File 'lib/pdfh/utils/console.rb', line 54 def ident_print(field, value, color: :green, width: 3) field_str = field.to_s.rjust(width) value_str = value.colorize(color) output "#{" " * 4}#{field_str}: #{value_str}" end |
#info(message) ⇒ void
This method returns an undefined value.
19 20 21 |
# File 'lib/pdfh/utils/console.rb', line 19 def info() output() end |
#print_options(options) ⇒ void
This method returns an undefined value.
Show options used to run the current sync job
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pdfh/utils/console.rb', line 63 def () # rubocop:disable Metrics/CyclomaticComplexity max_size = .keys.map(&:size).max + 3 .each do |key, value| left = key.inspect.rjust(max_size).cyan right = case value when NilClass then value.inspect.colorize(color: :black, mode: :bold) when TrueClass then value.inspect.colorize(color: :green, mode: :bold) when FalseClass then value.inspect.colorize(color: :red, mode: :bold) when Symbol then value.inspect.yellow when String then value.inspect.light_magenta else value.inspect.red end debug "#{left} => #{right}" end nil end |
#warn_print(message) ⇒ void
This method returns an undefined value.
46 47 48 |
# File 'lib/pdfh/utils/console.rb', line 46 def warn_print() output "Warning, #{}".colorize(:yellow) end |