Class: Surveyor::Common

Inherits:
Object
  • Object
show all
Defined in:
lib/surveyor/common.rb

Constant Summary collapse

OPERATORS =
%w(== != < > <= >= =~)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_api_idObject



37
38
39
# File 'lib/surveyor/common.rb', line 37

def generate_api_id
  UUIDTools::UUID.random_create.to_s
end

.to_normalized_string(text) ⇒ Object Also known as: normalize



24
25
26
27
28
29
30
31
32
33
# File 'lib/surveyor/common.rb', line 24

def 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.to_s.gsub(/(<[^>]*>)|\n|\t/su, ' ') # Remove html tags
  col_text.downcase!                            # Remove capitalization
  col_text.gsub!(/\"|\'/u, '')                   # Remove potential problem characters
  col_text.gsub!(/\(.*?\)/u,'')                  # Remove text inside parens
  col_text.gsub!(/\W/u, ' ')                     # Remove all other non-word characters
  cols = (col_text.split(' ') - words_to_omit)
  (cols.size > 5 ? cols[-5..-1] : cols).join("_")
end

Instance Method Details

#make_tiny_codeObject



10
11
12
13
14
# File 'lib/surveyor/common.rb', line 10

def make_tiny_code
  # 7 random bytes is increased to ~10 characters (sans padding) by
  # base64 encoding
  SecureRandom.urlsafe_base64(7)
end