Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/usefull_tools/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#linkerizeObject

Find links into string and create html links



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/usefull_tools/core_ext/string.rb', line 4

def linkerize
	content = self
	match = self.scan(/((http|https)\S*)/)
	if match.any?
		links = match.flatten.reject{|e| e =~ /(http$|https$)/}
		links.each do |link|
			content = content.gsub(link, "<a href='#{link}'>#{link}</a>")
		end
	end
	content
end

#to_boolObject

Return bool from string

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/usefull_tools/core_ext/string.rb', line 17

def to_bool
	return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
	return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
	raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end