Module: Surveyor
- Defined in:
- lib/surveyor.rb,
lib/surveyor/config.rb,
lib/surveyor/acts_as_response.rb
Defined Under Namespace
Modules: Response
Classes: Config
Constant Summary
collapse
- RAND_CHARS =
[('a'..'z'), ('A'..'Z'), (0..9)].map{|r| r.to_a}.flatten.to_s
Class Method Summary
collapse
Class Method Details
.make_tiny_code(len = 10) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/surveyor.rb', line 5
def self.make_tiny_code(len = 10)
if RUBY_VERSION < "1.8.7"
(1..len).to_a.map{|i| RAND_CHARS[rand(RAND_CHARS.size), 1] }.to_s
else
len.times.map{|i| RAND_CHARS[rand(RAND_CHARS.size), 1] }.to_s
end
end
|
.to_normalized_string(text) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/surveyor.rb', line 13
def self.to_normalized_string(text)
words_to_omit = %w(a be but has have in is it of on or the to when)
col_text = text.gsub(/(<[^>]*>)|\n|\t/s, ' ') col_text.downcase! col_text.gsub!(/\"|\'/, '') col_text.gsub!(/\(.*?\)/,'') col_text.gsub!(/\W/, ' ') cols = (col_text.split(' ') - words_to_omit)
(cols.size > 5 ? cols[-5..-1] : cols).join("_")
end
|