Class: Megam::Text
- Inherits:
-
Object
- Object
- Megam::Text
- Defined in:
- lib/megam/core/text.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #color(string, *colors) ⇒ Object
-
#color? ⇒ Boolean
Should colored output be used ?.
-
#err(message) ⇒ Object
Prints a msg to stderr.
-
#error(message) ⇒ Object
Print an error message.
-
#fatal(message) ⇒ Object
Print a message describing a fatal error.
- #highline ⇒ Object
-
#info(message) ⇒ Object
Prints a message to stdout.
-
#initialize(stdout, stderr, stdin, config) ⇒ Text
constructor
A new instance of Text.
- #list(*args) ⇒ Object
- #msg(message) ⇒ Object
- #pretty_print(data) ⇒ Object
-
#summarize(data) ⇒ Object
Summarize the data.
-
#text_format(data) ⇒ Object
Converts the
data
to a String in the text format. -
#warn(message) ⇒ Object
Print a warning message.
Constructor Details
#initialize(stdout, stderr, stdin, config) ⇒ Text
Returns a new instance of Text.
24 25 26 |
# File 'lib/megam/core/text.rb', line 24 def initialize(stdout, stderr, stdin, config) @stdout, @stderr, @stdin, @config = stdout, stderr, stdin, config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
23 24 25 |
# File 'lib/megam/core/text.rb', line 23 def config @config end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
21 22 23 |
# File 'lib/megam/core/text.rb', line 21 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
22 23 24 |
# File 'lib/megam/core/text.rb', line 22 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
20 21 22 |
# File 'lib/megam/core/text.rb', line 20 def stdout @stdout end |
Instance Method Details
#color(string, *colors) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/megam/core/text.rb', line 78 def color(string, *colors) if color? highline.color(string, *colors) else string end end |
#color? ⇒ Boolean
Should colored output be used ?. When output is not to a terminal, colored output is never used
88 89 90 |
# File 'lib/megam/core/text.rb', line 88 def color? stdout.tty? end |
#err(message) ⇒ Object
Prints a msg to stderr. Used for warn, error, and fatal.
59 60 61 |
# File 'lib/megam/core/text.rb', line 59 def err() stderr.puts end |
#error(message) ⇒ Object
Print an error message
69 70 71 |
# File 'lib/megam/core/text.rb', line 69 def error() err("#{color('ERROR:', :red, :bold)} #{}") end |
#fatal(message) ⇒ Object
Print a message describing a fatal error.
74 75 76 |
# File 'lib/megam/core/text.rb', line 74 def fatal() err("#{color('FATAL:', :red, :bold)} #{}") end |
#highline ⇒ Object
28 29 30 31 32 33 |
# File 'lib/megam/core/text.rb', line 28 def highline @highline ||= begin require 'highline' HighLine.new end end |
#info(message) ⇒ Object
Prints a message to stdout. Aliased as info
for compatibility with the logger API.
54 55 56 |
# File 'lib/megam/core/text.rb', line 54 def info() stdout.puts("#{color('INFO:', :green, :bold)} #{}") end |
#list(*args) ⇒ Object
92 93 94 |
# File 'lib/megam/core/text.rb', line 92 def list(*args) highline.list(*args) end |
#msg(message) ⇒ Object
47 48 49 |
# File 'lib/megam/core/text.rb', line 47 def msg() stdout.puts end |
#pretty_print(data) ⇒ Object
96 97 98 |
# File 'lib/megam/core/text.rb', line 96 def pretty_print(data) stdout.puts data end |
#summarize(data) ⇒ Object
Summarize the data. Defaults to text format output, which may not be very summary-like
37 38 39 |
# File 'lib/megam/core/text.rb', line 37 def summarize(data) text_format(data) end |
#text_format(data) ⇒ Object
Converts the data
to a String in the text format. Uses Chef::Knife::Core::TextFormatter
43 44 45 |
# File 'lib/megam/core/text.rb', line 43 def text_format(data) Megam::TextFormatter.new(data, self).formatted_data end |
#warn(message) ⇒ Object
Print a warning message
64 65 66 |
# File 'lib/megam/core/text.rb', line 64 def warn() err("#{color('WARNING:', :yellow, :bold)} #{}") end |