Sha256: 4c7d1aa2a3de7724b78d77ef3a5383d93b79353b31a15ced27e13872fae6dd75

Contents?: true

Size: 1.33 KB

Versions: 14

Compression:

Stored size: 1.33 KB

Contents

module TinyCode

  module ClassMethods

    RAND_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "abcdefghijklmnopqrstuvwxyz"

    def make_tiny_code
      random_string(10)
    end

    def random_string(len)
      rand_max = RAND_CHARS.size
      ret = "" 
      len.times{ ret << RAND_CHARS[rand(rand_max)] }
      ret 
    end


    def self.to_normalized_string(text)
      words_to_omit = ["a", "to", "the", "of", "has", "have", "it", "is", "in", "on", "or", "but", "when", "be"]

      # strip all the html tags from the text data
      col_text = text.gsub(/(<[^>]*>)|\n|\t/s, ' ')

      # Removing capitalization
      col_text.downcase!
      # Removing potential problem characters
      col_text.gsub!(/\"|\'/, '')
      # Removing text inside parens
      col_text.gsub!(/\(.*?\)/,'')

      # Removing all other non-word characters
      col_text.gsub!(/\W/, ' ')

      column_words = []
      words = col_text.split(' ')
      words.each do |word|
        if !words_to_omit.include?(word)
          column_words << word
        end
      end

      #reducing the word list to limit column length
      if column_words.length > 5
        column_words.slice!(0, column_words.length - 5)
      end

      #re-assemble the string
      column_words.join("_")
    end 

  end

  def self.included(klass)
    klass.extend(ClassMethods)
  end

end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
breakpointer-surveyor-0.2.0 lib/tiny_code.rb
surveyor-0.8.0 lib/tiny_code.rb
surveyor-0.7.1 lib/tiny_code.rb
surveyor-0.7.0 lib/tiny_code.rb
surveyor-0.6.10 lib/tiny_code.rb
surveyor-0.6.9 lib/tiny_code.rb
surveyor-0.6.8 lib/tiny_code.rb
surveyor-0.6.7 lib/tiny_code.rb
surveyor-0.6.6 lib/tiny_code.rb
surveyor-0.6.5 lib/tiny_code.rb
surveyor-0.6.4 lib/tiny_code.rb
surveyor-0.6.3 lib/tiny_code.rb
surveyor-0.6.2 lib/tiny_code.rb
surveyor-0.6.1 lib/tiny_code.rb