Class: String

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.randomize(length = 8) ⇒ Object



25
26
27
# File 'lib/sunrise/core_ext/string.rb', line 25

def self.randomize(length = 8)
  Array.new(length) { (rand(122-97) + 97).chr }.join
end

Instance Method Details

#is_int?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/sunrise/core_ext/string.rb', line 2

def is_int?
  self =~ /^[-+]?[0-9]*$/
end

#no_htmlObject



6
7
8
9
10
11
12
# File 'lib/sunrise/core_ext/string.rb', line 6

def no_html
	str = self.dup
	str.gsub!(/<\/?[^>]*>/, '')
	str.strip!
	str.gsub!('&nbsp;', '')
	str
end

#parameterize(sep = '-') ⇒ Object



20
21
22
23
# File 'lib/sunrise/core_ext/string.rb', line 20

def parameterize(sep = '-')
 value = Sunrise::Utils::Transliteration.transliterate(self)
  ActiveSupport::Inflector.parameterize(value, sep)
end

#words_countObject



14
15
16
17
18
# File 'lib/sunrise/core_ext/string.rb', line 14

def words_count
	frequencies = Hash.new(0)  
	downcase.scan(/(\w+([-'.]\w+)*)/) { |word, ignore| frequencies[word] += 1 }
	return frequencies
end