Class: String

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

Instance Method Summary collapse

Instance Method Details

#occurrencesObject



9
10
11
# File 'lib/wc.rb', line 9

def occurrences
  Wc::Engine.read_inline(self)
end

#to_tag_cloud(max_words = nil) ⇒ Object



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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/wc.rb', line 13

def to_tag_cloud(max_words = nil)

  sorted = self.occurrences

  if max_words.nil?
    cloud_items = sorted
  else
    cloud_items = sorted[0..max_words-1]
  end

  max = sorted.first[1]
  min = sorted.last[1]
  
  range = max - min
  interval = (1.0 * range)/10
  
  r0=min+interval
  r1=r0+interval
  r2=r1+interval
  r3=r2+interval
  r4=r3+interval
  r5=r4+interval
  r6=r5+interval
  r7=r6+interval
  r8=r7+interval
  r9=r8+interval
  r10=r9+interval
  
  ret = "<ul id=\"cloud\">"
  
  cloud_items.each { |elem|
    if (elem[1]>r10)
      c="tag9"
    elsif (elem[1] > r9)
      c="tag8"
    elsif (elem[1] > r8)
      c="tag7"
    elsif (elem[1] > r7)
      c="tag6"
    elsif (elem[1] > r6)
      c="tag5"
    elsif (elem[1] > r5)
      c="tag4"
    elsif (elem[1] > r4)
      c="tag3"
    elsif (elem[1] > r3)
      c="tag2"
    elsif (elem[1] > r2)
      c="tag1"
    else
      c="tag0"
    end
  
    ret+="<li><a href=\"#\" class=\""+c+"\">" + elem[0] +"</a></li>"
    
  }
  ret += "</ul>"
  ret
end

#wcObject



5
6
7
# File 'lib/wc.rb', line 5

def wc
  self.occurrences.size
end