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.
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.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pow.rb', line 55 def initialize(*args) = args[0].is_a?(Hash) ? args[0] : {:text => args[0].to_s}.merge(args[1] || {}) 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]) [:strikethrough] ||= [:misc][:strikethrough] end @writer = [:writer] || STDOUT @formatted_text = format_string() out!(@formatted_text) end |
Instance Attribute Details
#writer ⇒ Object
Returns the value of attribute writer.
54 55 56 |
# File 'lib/pow.rb', line 54 def writer @writer end |
Instance Method Details
#inspect ⇒ Object
96 97 98 |
# File 'lib/pow.rb', line 96 def inspect nil end |
#out!(string = nil) ⇒ Object
Write the coloured text to IO
79 80 81 82 83 |
# File 'lib/pow.rb', line 79 def out!(string=nil) if string && string != "" printf(writer, string) end end |
#painbow(*args) ⇒ Object
Feel the painbow
91 92 93 94 |
# File 'lib/pow.rb', line 91 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
85 86 87 88 |
# File 'lib/pow.rb', line 85 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 |