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.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tagcloudbase.rb', line 15

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.



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

def to_dynarex
  @to_dynarex
end

#xslObject

Returns the value of attribute xsl.



13
14
15
# File 'lib/tagcloudbase.rb', line 13

def xsl
  @xsl
end

Instance Method Details

#to_webpageObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tagcloudbase.rb', line 34

def to_webpage()
  
  lib = File.dirname(__FILE__)
  xsl = File.read lib + '/tagcloud.xsl'
  css = File.read lib + '/tagcloud.css'

  doc   = Nokogiri::XML(@to_dynarex.to_xml)
  xslt  = Nokogiri::XSLT(@xsl || xsl)    
  html = xslt.transform(Nokogiri::XML(@to_dynarex.to_xml))

  return {html: html, css: css}
end