Class: Kieran_gem

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

Class Method Summary collapse

Class Method Details

.hi(text) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kieran_gem.rb', line 3

def self.hi(text)
  
  @result = text


  @words = []
  @cleanWords =[]  

  @result.each do |x|
   #words = []
   #@cleanWords =[]
    #get the values only from the hash
    values = x.values
  
    #convert it to string 
    strValue = values.to_s
    #to utf 8
    encodedValue = strValue.gsub(160.chr("UTF-8"),"") # this beautiful little function removes   -> LIFE SAVER
    #puts encodedValue
    # remove html tags
    rmvHtml = encodedValue.gsub(/(<[^>]*>)|\n|\t/s) {""}  
    
    # remove additional chars
    rmvExtraChars = rmvHtml.tr('[]',"")
    # still some chars left, gotta get rid of them
    again = rmvExtraChars.delete('\\"')
    #split each by white space
    #word = again.split(' ')
    #word is an array covert back to string
    newWord =again.to_s
    @words.push(newWord)
    end
    #p @words
    @words.each do |ugh|
     dog = ugh.split(" ")
      dog.each do |mouse|
        @cleanWords.push(mouse)
       #p @cleanWords
      end
    end
    p @cleanWords
end