lib/nanoc/toolbox/helpers/tagging_extra.rb
# Sort the tags of an item collection (defaults to all site items) in 'n'
# classes of rank. The rank 0 corresponds to the most frequent tags.
# The rank 'n-1' to the least frequents. The result is a hash such as:
# { tag => rank }
#
# @param [Integer] n number of rank
# @param [Array<Nanoc::Item>] items
Sort the tags of an item collection (defaults to all site items) in 'n'
classes of rank. The rank 0 corresponds to the most frequent tags.
The rank 'n-1' to the least frequents. The result is a hash such as:
{ tag => rank }
Sort the tags of an item collection ( defaults to all site items ) in ' n ' classes of rank . The rank 0 corresponds to the most frequent tags . The rank ' n - 1 ' to the least frequents . The result is a hash such as : { tag = > rank }
def rank_tags(n, items=nil)
      raise ArgumentError, 'the number of ranks should be > 1' if n < 2
      items = @items if items.nil?
      count = count_tags( items )
      min, max = count.values.minmax
      ranker = lambda { |num| n - 1 - (num - min) / (max - min) }
      Hash[count.map {|tag,value| [tag, ranker.call(value) ] }]
    end
def rank_tags ( n , items = nil ) raise ArgumentError , 'the number of ranks should be > 1' if n < 2 items = @items if items . nil? count = count_tags ( items ) min , max = count . values . minmax ranker = lambda { | num | n - 1 - ( num - min ) / ( max - min ) } Hash [ count . map { | tag , value | [ tag , ranker . call ( value ) ] } ] end
Sort the tags of an item collection (defaults to all site items) in 'n'
classes of rank.
Sort the tags of an item collection ( defaults to all site items ) in ' n ' classes of rank .
n
items
None