module SemanticallyTaggable
  module TagsHelper
    def tag_cloud(tags, classes)
      tags = tags.all if tags.respond_to?(:all)

      return [] if tags.empty?

      max_count = tags.sort_by(&:count).last.count.to_f

      tags.each do |tag|
        index = ((tag.count / max_count) * (classes.size - 1)).round
        yield tag, classes[index]
      end
    end
  end
end