Class: Cmessages
- Inherits:
-
Object
- Object
- Cmessages
- Defined in:
- lib/cmessages.rb,
lib/cmessages/version.rb
Overview
Docs to follow
Constant Summary collapse
- VERSION =
'1.0.1'.freeze
Instance Method Summary collapse
- #error(message = nil) ⇒ Object
- #info(message = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Cmessages
constructor
A new instance of Cmessages.
- #real_show_message(prefix, message, colour) ⇒ Object
- #success(message = nil) ⇒ Object
- #valid_colour(colour) ⇒ Object
- #warning(message = nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Cmessages
Returns a new instance of Cmessages.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cmessages.rb', line 10 def initialize( = {}) @valid_colours = %I[black light_black red light_red green light_green yellow light_yellow blue light_blue magenta light_magenta cyan light_cyan white light_white default] @error_colour = :light_red @warning_colour = :light_yellow @success_colour = :light_green @info_colour = :light_cyan @error_prefix = '[ Error ]' @warning_prefix = '[ Warning ]' @success_prefix = '[ Success ]' @info_prefix = '[ Info ]' @use_colours = true unless .key?(:use_colours) && [:use_colours] == false @use_prefixes = true unless .key?(:use_prefixes) && [:use_prefixes] == false @error_colour = [:error_colour] if .key?(:error_colour) && valid_colour([:error_colour]) @warning_colour = [:warning_colour] if .key?(:warning_colour) && valid_colour([:warning_colour]) @success_colour = [:success_colour] if .key?(:success_colour) && valid_colour([:success_colour]) @info_colour = [:info_colour] if .key?(:info_colour) && valid_colour([:info_colour]) @error_prefix = [:error_prefix] if .key?(:error_prefix) @warning_prefix = [:warning_prefix] if .key?(:warning_prefix) @success_prefix = [:success_prefix] if .key?(:success_prefix) @info_prefix = [:info_prefix] if .key?(:info_prefix) end |
Instance Method Details
#error(message = nil) ⇒ Object
41 42 43 44 45 |
# File 'lib/cmessages.rb', line 41 def error( = nil) return if .nil? (@error_prefix, , @error_colour) end |
#info(message = nil) ⇒ Object
59 60 61 62 63 |
# File 'lib/cmessages.rb', line 59 def info( = nil) return if .nil? (@info_prefix, , @info_colour) end |
#real_show_message(prefix, message, colour) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cmessages.rb', line 65 def (prefix, , colour) return if .nil? return if .empty? # String contains 0 or more white-space character and nothing else. return if =~ /\A\s*\z/ = "#{prefix} #{}" if @use_prefixes if @use_colours puts .colorize(colour) else puts end end |
#success(message = nil) ⇒ Object
53 54 55 56 57 |
# File 'lib/cmessages.rb', line 53 def success( = nil) return if .nil? (@success_prefix, , @success_colour) end |
#valid_colour(colour) ⇒ Object
37 38 39 |
# File 'lib/cmessages.rb', line 37 def valid_colour(colour) return @valid_colours.include?(colour) end |
#warning(message = nil) ⇒ Object
47 48 49 50 51 |
# File 'lib/cmessages.rb', line 47 def warning( = nil) return if .nil? (@warning_prefix, , @warning_colour) end |