Module: Octospy::Extensions::String
- Defined in:
- lib/octospy/extensions/string.rb
Instance Method Summary collapse
- #colorize_for_irc ⇒ Object
- #compact ⇒ Object
- #shorten_url ⇒ Object (also: #shorten)
- #split_by_linefeed_except_blankline ⇒ Object (also: #split_lfbl)
- #to_boolean ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#colorize_for_irc ⇒ Object
24 25 26 |
# File 'lib/octospy/extensions/string.rb', line 24 def colorize_for_irc StringIrc.new(self) end |
#compact ⇒ Object
20 21 22 |
# File 'lib/octospy/extensions/string.rb', line 20 def compact self.gsub(/\s+/, ' ').strip end |
#shorten_url ⇒ Object Also known as: shorten
35 36 37 |
# File 'lib/octospy/extensions/string.rb', line 35 def shorten_url Octospy::Url.shorten self end |
#split_by_linefeed_except_blankline ⇒ Object Also known as: split_lfbl
15 16 17 |
# File 'lib/octospy/extensions/string.rb', line 15 def split_by_linefeed_except_blankline self.split(/\r\n|\n/).map { |v| v unless v.eql? '' }.compact end |
#to_boolean ⇒ Object
28 29 30 31 32 33 |
# File 'lib/octospy/extensions/string.rb', line 28 def to_boolean case self when 'true' then true when 'false' then false end end |
#underscore ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/octospy/extensions/string.rb', line 7 def underscore self.gsub('::', '/'). gsub(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |