Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/usefull_tools/core_ext/string.rb
Instance Method Summary collapse
-
#linkerize ⇒ Object
Find links into string and create html links.
-
#to_bool ⇒ Object
Return bool from string.
Instance Method Details
#linkerize ⇒ Object
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_bool ⇒ Object
Return bool from string
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 |