Module: Inkjet::Colors::Formatters
- Included in:
- Inkjet
- Defined in:
- lib/inkjet/colors.rb
Class Method Summary
collapse
Instance Method Summary
collapse
-
#colorize(color, str, wrap = false) ⇒ Object
-
#colorize!(color, str, wrap = false) ⇒ Object
-
#colorize_background(color, str, wrap = false) ⇒ Object
-
#colorize_background!(color, str, wrap = false) ⇒ Object
-
#colorize_with_background(fg_color, bg_color, str, wrap = false) ⇒ Object
-
#colorize_with_background!(fg_color, bg_color, str, wrap = false) ⇒ Object
-
#method_missing(meth, *args) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/inkjet/colors.rb', line 67
def method_missing(meth, *args)
if meth.match(/\A(#{Inkjet::Colors::Colors.push("default").join("|")})_text(!?)\Z/)
colorize($1, *args) elsif meth.match(/\A(#{Inkjet::Colors::Colors.push("default").join("|")})_(background|bg)(!?)\Z/)
colorize_background($1, *args) elsif meth.match(/\A(#{Inkjet::Colors::Colors.push("default").join("|")})_(#{Inkjet::Colors::Colors.push("default").join("|")})(!?)\Z/)
colorize_with_background($1, $2, *args) else
super
end
end
|
Class Method Details
.included(base) ⇒ Object
39
40
41
|
# File 'lib/inkjet/colors.rb', line 39
def self.included(base)
base.send :extend, self
end
|
Instance Method Details
#colorize(color, str, wrap = false) ⇒ Object
43
44
45
|
# File 'lib/inkjet/colors.rb', line 43
def colorize(color, str, wrap=false)
colorize!(color, str.clone, wrap)
end
|
#colorize!(color, str, wrap = false) ⇒ Object
47
48
49
|
# File 'lib/inkjet/colors.rb', line 47
def colorize!(color, str, wrap=false)
str.apply_inkjet_code!(Inkjet::Colors.foreground(color), wrap)
end
|
#colorize_background(color, str, wrap = false) ⇒ Object
51
52
53
|
# File 'lib/inkjet/colors.rb', line 51
def colorize_background(color, str, wrap=false)
colorize_background!(color, str.clone, wrap)
end
|
#colorize_background!(color, str, wrap = false) ⇒ Object
55
56
57
|
# File 'lib/inkjet/colors.rb', line 55
def colorize_background!(color, str, wrap=false)
str.apply_inkjet_code!(Inkjet::Colors.background(color), wrap)
end
|
#colorize_with_background(fg_color, bg_color, str, wrap = false) ⇒ Object
59
60
61
|
# File 'lib/inkjet/colors.rb', line 59
def colorize_with_background(fg_color, bg_color, str, wrap=false)
colorize_with_background!(fg_color, bg_color, str.clone, wrap)
end
|
#colorize_with_background!(fg_color, bg_color, str, wrap = false) ⇒ Object
63
64
65
|
# File 'lib/inkjet/colors.rb', line 63
def colorize_with_background!(fg_color, bg_color, str, wrap=false)
str.apply_inkjet_codes!([Inkjet::Colors.foreground(fg_color), Inkjet::Colors.background(bg_color)], wrap)
end
|