class Contraption::TagCloud

Public Class Methods

new(posts) click to toggle source
# File lib/contraption/tag_cloud.rb, line 3
def initialize posts
  @posts = posts
end

Public Instance Methods

to_s() click to toggle source
# File lib/contraption/tag_cloud.rb, line 7
def to_s
  @posts.by_tag
        .each_pair
        .map {|k, v| [tag_link(k), tag_size(v.length)]}
        .map {|el| scale el}
        .join "\n"
end

Private Instance Methods

max() click to toggle source
# File lib/contraption/tag_cloud.rb, line 27
def max
  @posts.by_tag.each_pair.map {|k, v| v.length}.max
end
scale(element) click to toggle source
# File lib/contraption/tag_cloud.rb, line 21
def scale element
  link = element.first
  size = element.last
  %Q{<span style="font-size: #{size}em;">#{link}</span>}
end
tag_size(length) click to toggle source
# File lib/contraption/tag_cloud.rb, line 31
def tag_size length
  (1 + length.to_f/max) * 0.8
end