Class: FOut
Overview
stdout manager
module FOut
Instance Method Summary collapse
- #approved_fout?(level) ⇒ Boolean
-
#fetch_display_level ⇒ Object
integer value for comparison.
-
#fetch_display_level_xbase_prefix ⇒ Object
integer value for comparison.
-
#fout(str) ⇒ Object
standard output; not for debug.
-
#fout_list(str) ⇒ Object
‘puts` guarantees exactly one line break per item it prints.
- #fout_section(name, data) ⇒ Object
-
#initialize(config) ⇒ FOut
constructor
A new instance of FOut.
-
#lout(str, level: DISPLAY_LEVEL_BASE) ⇒ Object
display output at level or lower than filter (DISPLAY_LEVEL_DEFAULT).
Constructor Details
#initialize(config) ⇒ FOut
Returns a new instance of FOut.
10 11 12 |
# File 'lib/fout.rb', line 10 def initialize(config) @config = config end |
Instance Method Details
#approved_fout?(level) ⇒ Boolean
14 15 16 |
# File 'lib/fout.rb', line 14 def approved_fout?(level) level <= fetch_display_level end |
#fetch_display_level ⇒ Object
integer value for comparison
20 21 22 |
# File 'lib/fout.rb', line 20 def fetch_display_level @config.fetch(:display_level, 1) end |
#fetch_display_level_xbase_prefix ⇒ Object
integer value for comparison
26 27 28 |
# File 'lib/fout.rb', line 26 def fetch_display_level_xbase_prefix @config.fetch(:level_xbase_prefix, '') end |
#fout(str) ⇒ Object
standard output; not for debug
32 33 34 |
# File 'lib/fout.rb', line 32 def fout(str) puts str end |
#fout_list(str) ⇒ Object
‘puts` guarantees exactly one line break per item it prints. For each argument (and for each element when given an Array), it appends a newline only if the string does not already end with “n”. If it does, `puts` does not add another. Net effect: trailing newlines in your data are consumed rather than duplicated, so “Linen” does not create a blank line.
41 42 43 |
# File 'lib/fout.rb', line 41 def fout_list(str) puts str end |
#fout_section(name, data) ⇒ Object
45 46 47 48 |
# File 'lib/fout.rb', line 45 def fout_section(name, data) puts "# #{name}" puts data.to_yaml end |
#lout(str, level: DISPLAY_LEVEL_BASE) ⇒ Object
display output at level or lower than filter (DISPLAY_LEVEL_DEFAULT)
52 53 54 55 56 |
# File 'lib/fout.rb', line 52 def lout(str, level: DISPLAY_LEVEL_BASE) return unless approved_fout?(level) fout level == DISPLAY_LEVEL_BASE ? str : fetch_display_level_xbase_prefix + str end |