Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/pickaxe/extensions.rb

Direct Known Subclasses

Pickaxe::TestLine

Instance Method Summary collapse

Instance Method Details

#color(name, bold = false) ⇒ Object



23
24
25
# File 'lib/pickaxe/extensions.rb', line 23

def color(name, bold=false)
	Pickaxe::Color.set_color(self, name, bold)
end

#word_wrap(*args) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pickaxe/extensions.rb', line 2

def word_wrap(*args)
	options = args.extract_options!
	unless args.blank?
		options[:line_width] = args[0] || Pickaxe::Shell.dynamic_width || 80
	end
	options.reverse_merge!({
		:line_width => (Pickaxe::Shell.dynamic_width || 80),
		:indent => 0
	})
	
	options[:line_width] -= options[:indent]

	self.split("\n").collect do |line|
		if line.length > options[:line_width]
		 line.gsub(/(.{1,#{options[:line_width]}})(\s+|$)/, "\\1\n#{" " * options[:indent]}").strip
		else
			line.strip
		end
	end * "\n#{" " * options[:indent]}"
end