Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/sunrise/core_ext/string.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.randomize(length = 8) ⇒ Object
27 28 29 |
# File 'lib/sunrise/core_ext/string.rb', line 27 def self.randomize(length = 8) Array.new(length) { (rand(122-97) + 97).chr }.join end |
Instance Method Details
#is_int? ⇒ Boolean
4 5 6 |
# File 'lib/sunrise/core_ext/string.rb', line 4 def is_int? self =~ /^[-+]?[0-9]*$/ end |
#no_html ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/sunrise/core_ext/string.rb', line 8 def no_html str = self.dup str.gsub!(/<\/?[^>]*>/, '') str.strip! str.gsub!(' ', '') str end |
#parameterize(sep = '-') ⇒ Object
22 23 24 25 |
# File 'lib/sunrise/core_ext/string.rb', line 22 def parameterize(sep = '-') value = Sunrise::Utils::Transliteration.transliterate(self) ActiveSupport::Inflector.parameterize(value, sep) end |
#words_count ⇒ Object
16 17 18 19 20 |
# File 'lib/sunrise/core_ext/string.rb', line 16 def words_count frequencies = Hash.new(0) downcase.scan(/(\w+([-'.]\w+)*)/) { |word, ignore| frequencies[word] += 1 } return frequencies end |