Class: TagCloudBase
- Inherits:
-
Object
- Object
- TagCloudBase
- Defined in:
- lib/tagcloudbase.rb
Instance Attribute Summary collapse
-
#to_dynarex ⇒ Object
readonly
Returns the value of attribute to_dynarex.
-
#xsl ⇒ Object
Returns the value of attribute xsl.
Instance Method Summary collapse
-
#initialize(all_tags = {}) ⇒ TagCloudBase
constructor
A new instance of TagCloudBase.
- #to_webpage ⇒ Object
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(={}) = .sort_by {|x| -x[-1][-1].to_i} biggest_tag = .first[-1][-1].to_i # sort in alphabetical order = .sort_by &:first @to_dynarex = Dynarex.new('tags/tag(word,href,gauge,count)') .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_dynarex ⇒ Object (readonly)
Returns the value of attribute to_dynarex.
12 13 14 |
# File 'lib/tagcloudbase.rb', line 12 def to_dynarex @to_dynarex end |
#xsl ⇒ Object
Returns the value of attribute xsl.
13 14 15 |
# File 'lib/tagcloudbase.rb', line 13 def xsl @xsl end |
Instance Method Details
#to_webpage ⇒ Object
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 |