Class: Pow::Puts
- Inherits:
-
Object
- Object
- Pow::Puts
- Defined in:
- lib/pow.rb
Instance Attribute Summary collapse
-
#writer ⇒ Object
Returns the value of attribute writer.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ Puts
constructor
A new instance of Puts.
- #inspect ⇒ Object
-
#out!(string = nil) ⇒ Object
Write the coloured text to IO.
-
#painbow(*args) ⇒ Object
Feel the painbow.
- #rainbow(*args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Puts
Returns a new instance of Puts.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/pow.rb', line 101 def initialize(*args) = args[0].is_a?(Hash) ? args[0] : {:text => args[0].to_s}.merge(args[1] || {}) rescue {:text => args[0]} @@match_color = :red CODES.keys.each do |key| # Color self.class.send(:define_method, key.to_sym) { |*args| Puts.new({:color => key.to_sym, :text => args[0], :misc => args[1]}).out! } # Bold self.class.send(:define_method, "#{key}!".to_sym) { |*args| Puts.new({:color => key.to_sym, :text => args[0], :bold => true, :misc => args[1]}).out! } # Underline self.class.send(:define_method, "#{key}_".to_sym) { |*args| Puts.new({:color => key.to_sym, :text => args[0], :underline => true, :misc => args[1]}).out! } end # FIXME make this part a method or less fug if [:misc] && [:misc].is_a?(Hash) [:bold] ||= [:misc][:bold] [:negative] ||= [:misc][:negative] [:underline] ||= [:misc][:underline] [:background] ||= ([:misc][:background] || [:misc][:on]) [:on] ||= [:background] [:strikethrough] ||= [:misc][:strikethrough] [:match] ||= [:misc][:match] [:match_color] ||= [:misc][:match_color] end @@color = [:color] || :white @writer = [:writer] || STDOUT @formatted_text = Pow.enabled? ? format_string() : [:text] + "\n" out!(@formatted_text) end |
Instance Attribute Details
#writer ⇒ Object
Returns the value of attribute writer.
100 101 102 |
# File 'lib/pow.rb', line 100 def writer @writer end |
Class Method Details
.color ⇒ Object
130 131 132 |
# File 'lib/pow.rb', line 130 def color @@color end |
.match_color ⇒ Object
138 139 140 |
# File 'lib/pow.rb', line 138 def match_color @@match_color end |
.match_color=(val) ⇒ Object
134 135 136 |
# File 'lib/pow.rb', line 134 def match_color=(val) @@match_color = val end |
Instance Method Details
#inspect ⇒ Object
161 162 163 |
# File 'lib/pow.rb', line 161 def inspect @formatted_text.inspect end |
#out!(string = nil) ⇒ Object
Write the coloured text to IO
144 145 146 147 148 |
# File 'lib/pow.rb', line 144 def out!(string=nil) if string && string != "" printf(writer, string) end end |
#painbow(*args) ⇒ Object
Feel the painbow
156 157 158 159 |
# File 'lib/pow.rb', line 156 def painbow(*args) text = args[0] out!(text.to_s.split("").inject(""){|m, word| m+= format_string(:text => word, :bold => true, :newline => "", :color => painbow_keys.sort_by{|k| rand}[0]) + " " } + "\n") end |
#rainbow(*args) ⇒ Object
150 151 152 153 |
# File 'lib/pow.rb', line 150 def rainbow(*args) text = args[0] out!(text.to_s.split("").inject(""){|m, word| m+= format_string(:text => word, :bold => true, :newline => "", :color => rainbow_keys.sort_by{|k| rand}[0]) + " " } + "\n") end |