class TagStats

Public Class Methods

new(tagCollection) click to toggle source
# File lib/tagStats.rb, line 3
def initialize(tagCollection)
  @tags = tagCollection.getTags
end

Public Instance Methods

print() click to toggle source
printLessTableBody(firstColumn, secondColumn, changes) click to toggle source
# File lib/tagStats.rb, line 146
def printLessTableBody(firstColumn, secondColumn, changes)

  changeCount = 0
  prevCount = 0

  @tags.each do |tag, stats|
    
    firstColumnValue = stats[firstColumn]
    if (firstColumnValue > prevCount)
      changeCount += 1
      if (changeCount == changes)
        break
      end
    end
    prevCount = stats[firstColumn]

    secondColumnValue = stats[secondColumn]
    printRow(tag, firstColumnValue, secondColumnValue)

  end

end
printLessUnread() click to toggle source
# File lib/tagStats.rb, line 38
def printLessUnread
  @tags = @tags.sort_by{|_key, stats| stats['unread']}
  printTitle('     Tag Stats - Less Unread     ')
  printLessUnreadUntilChange(3)
  printSeparator
end
printLessUnreadUntilChange(changes) click to toggle source
# File lib/tagStats.rb, line 81
def printLessUnreadUntilChange(changes)
  printTableHeaderUnreadTotal
  printLessTableBody('unread', 'total', changes)
end
printLessUsed() click to toggle source
# File lib/tagStats.rb, line 24
def printLessUsed
  @tags = @tags.sort_by{|_key, stats| stats['total']}
  printTitle('      Tag Stats - Less Used      ')
  printLessUsedUntilChange(3)
  printSeparator
end
printLessUsedUntilChange(changes) click to toggle source
# File lib/tagStats.rb, line 71
def printLessUsedUntilChange(changes)
  printTableHeaderTotalUnread
  printLessTableBody('total', 'unread', changes)
end
printMostTableBody(firstColumn, secondColumn, changes) click to toggle source
# File lib/tagStats.rb, line 116
def printMostTableBody(firstColumn, secondColumn, changes)

  changeCount = 0
  firstLoop = true
  prevValue = 0

  @tags.each do |tag, stats|
    
    if (firstLoop)
      prevCount = stats[firstColumn]
      firstLoop = false
    end

    firstColumnValue = stats[firstColumn]
    if (firstColumnValue < prevValue)
      changeCount += 1
      if (changeCount == changes)
        break
      end
    end
    prevValue = firstColumnValue

    secondColumnValue = stats[secondColumn]
    printRow(tag, firstColumnValue, secondColumnValue)

  end

end
printMostUnread() click to toggle source
# File lib/tagStats.rb, line 31
def printMostUnread
  @tags = @tags.sort_by{|_key, stats| stats['unread']}.reverse!
  printTitle('     Tag Stats - Most Unread     ')
  printMostUnreadUntilChange(10)
  printSeparator
end
printMostUnreadUntilChange(changes) click to toggle source
# File lib/tagStats.rb, line 76
def printMostUnreadUntilChange(changes)
  printTableHeaderUnreadTotal
  printMostTableBody('unread', 'total', changes)
end
printMostUsed() click to toggle source
# File lib/tagStats.rb, line 17
def printMostUsed
  @tags = @tags.sort_by{|_key, stats| stats['total']}.reverse!
  printTitle('      Tag Stats - Most Used      ')
  printMostUsedUntilChange(10)
  printSeparator
end
printMostUsedUntilChange(changes) click to toggle source
# File lib/tagStats.rb, line 66
def printMostUsedUntilChange(changes)
  printTableHeaderTotalUnread
  printMostTableBody('total', 'unread',changes)
end
printRow(tag, firstColumnValue, secondColumnValue) click to toggle source
# File lib/tagStats.rb, line 111
def printRow(tag, firstColumnValue, secondColumnValue)
  puts sprintf "%-13s | %6d  | %7d", tag, firstColumnValue, secondColumnValue
end
printSeparator() click to toggle source
# File lib/tagStats.rb, line 106
def printSeparator
  puts '================================='
end
printSpecificTerms(terms) click to toggle source
# File lib/tagStats.rb, line 46
def printSpecificTerms(terms)
  
  specificTags = Hash.new
  terms.each do |term|
    if (@tags.has_key?(term))
      specificTags[term] = @tags[term]
    end
  end

  if (!specificTags.empty?)
    aux = @tags
    @tags = specificTags
    printMostUnread
    puts ''
    @tags = aux
  end

end
printTableHeader(firstColumn, secondColumn) click to toggle source
# File lib/tagStats.rb, line 95
def printTableHeader(firstColumn, secondColumn)
  puts sprintf "%-13s | %6s  | %7s", 'tag', firstColumn, secondColumn
  puts '---------------------------------'
end
printTableHeaderTotalUnread() click to toggle source
# File lib/tagStats.rb, line 86
def printTableHeaderTotalUnread
  printTableHeader('total', 'unread')
end
printTableHeaderUnreadTotal() click to toggle source
# File lib/tagStats.rb, line 90
def printTableHeaderUnreadTotal
  printTableHeader('unread', 'total')
end
printTitle(title) click to toggle source
# File lib/tagStats.rb, line 100
def printTitle(title)
  puts '================================='
  puts title
  puts '---------------------------------'
end