Class: TagCloudBase

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(all_tags = {}) ⇒ TagCloudBase

Returns a new instance of TagCloudBase.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tagcloudbase.rb', line 13

def initialize(all_tags={})
  tags = all_tags.sort_by {|x| -x[-1][-1].to_i}
  biggest_tag = tags.first[-1][-1].to_i
  # sort in alphabetical order
  abc_tags = tags.sort_by &:first

  @to_dynarex = Dynarex.new('tags/tag(word,href,gauge,count)')
  abc_tags.each do |word, v|
    href, word_size = v
    weight = 100 / (biggest_tag / word_size.to_i)
    gauge = (weight / 10).to_i
    gauge = 8 if gauge > 8
    @to_dynarex.create word: word, href: href, gauge: gauge.to_s, count: word_size
  end
end

Instance Attribute Details

#to_dynarexObject (readonly)

Returns the value of attribute to_dynarex.



10
11
12
# File 'lib/tagcloudbase.rb', line 10

def to_dynarex
  @to_dynarex
end

#xslObject

Returns the value of attribute xsl.



11
12
13
# File 'lib/tagcloudbase.rb', line 11

def xsl
  @xsl
end

Instance Method Details

#to_webpageObject



29
30
31
32
33
34
35
36
37
# File 'lib/tagcloudbase.rb', line 29

def to_webpage()
  
  lib = File.dirname(__FILE__)
  xsl = open(lib + '/tagcloud.xsl','UserAgent' => 'TagCloudBase').read
  css = open(lib + '/tagcloud.css','UserAgent' => 'TagCloudBase').read
  
  html = Rexslt.new(@xsl || xsl, @to_dynarex.to_xml).to_s
  return {html: html, css: css}
end