Class: TagStats
- Inherits:
-
Object
- Object
- TagStats
- Defined in:
- lib/tagStats.rb
Instance Method Summary collapse
-
#initialize(tagCollection) ⇒ TagStats
constructor
A new instance of TagStats.
- #print ⇒ Object
- #printLessUnread ⇒ Object
- #printLessUnreadUntilChange(changes) ⇒ Object
- #printLessUsed ⇒ Object
- #printLessUsedUntilChange(changes) ⇒ Object
- #printMostUnread ⇒ Object
- #printMostUnreadUntilChange(changes) ⇒ Object
- #printMostUsed ⇒ Object
- #printMostUsedUntilChange(changes) ⇒ Object
- #printTopTable ⇒ Object
Constructor Details
#initialize(tagCollection) ⇒ TagStats
Returns a new instance of TagStats.
3 4 5 |
# File 'lib/tagStats.rb', line 3 def initialize(tagCollection) @tags = tagCollection.getTags end |
Instance Method Details
#print ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/tagStats.rb', line 7 def print printMostUsed puts '' printLessUsed puts '' printMostUnread puts '' printLessUnread end |
#printLessUnread ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/tagStats.rb', line 44 def printLessUnread @tags = @tags.sort_by{|_key, stats| stats['unread']} puts '=================================' puts ' Tag Stats - Less Unread ' puts '---------------------------------' printLessUnreadUntilChange(3) puts '=================================' end |
#printLessUnreadUntilChange(changes) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/tagStats.rb', line 147 def printLessUnreadUntilChange(changes) puts sprintf "%-13s | %6s | %7s", 'tag', 'unread', 'total' puts '---------------------------------' changeCount = 0 prevCount = 0 @tags.each do |tag, stats| unread = stats['unread'] if (unread > prevCount) changeCount += 1 if (changeCount == changes) break end end prevCount = stats['unread'] count = stats['count'] puts sprintf "%-13s | %6d | %7d", tag, unread, count end end |
#printLessUsed ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/tagStats.rb', line 26 def printLessUsed @tags = @tags.sort_by{|_key, stats| stats['count']} puts '=================================' puts ' Tag Stats - Less Used ' puts '---------------------------------' printLessUsedUntilChange(3) puts '=================================' end |
#printLessUsedUntilChange(changes) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/tagStats.rb', line 87 def printLessUsedUntilChange(changes) puts sprintf "%-13s | %6s | %7s", 'tag', 'total', 'unread' puts '---------------------------------' changeCount = 0 prevCount = 0 @tags.each do |tag, stats| count = stats['count'] if (count > prevCount) changeCount += 1 if (changeCount == changes) break end end prevCount = stats['count'] unread = stats['unread'] puts sprintf "%-13s | %6d | %7d", tag, count, unread end end |
#printMostUnread ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/tagStats.rb', line 35 def printMostUnread @tags = @tags.sort_by{|_key, stats| stats['unread']}.reverse! puts '=================================' puts ' Tag Stats - Most Unread ' puts '---------------------------------' printMostUnreadUntilChange(10) puts '=================================' end |
#printMostUnreadUntilChange(changes) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/tagStats.rb', line 114 def printMostUnreadUntilChange(changes) puts sprintf "%-13s | %6s | %7s", 'tag', 'unread', 'total' puts '---------------------------------' changeCount = 0 firstLoop = true prevCount = 0 @tags.each do |tag, stats| if (firstLoop) prevCount = stats['unread'] firstLoop = false end unread = stats['unread'] if (unread < prevCount) changeCount += 1 if (changeCount == changes) break end end prevCount = stats['unread'] count = stats['count'] puts sprintf "%-13s | %6d | %7d", tag, unread, count end end |
#printMostUsed ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/tagStats.rb', line 17 def printMostUsed @tags = @tags.sort_by{|_key, stats| stats['count']}.reverse! puts '=================================' puts ' Tag Stats - Most Used ' puts '---------------------------------' printMostUsedUntilChange(10) puts '=================================' end |
#printMostUsedUntilChange(changes) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tagStats.rb', line 54 def printMostUsedUntilChange(changes) puts sprintf "%-13s | %6s | %7s", 'tag', 'total', 'unread' puts '---------------------------------' changeCount = 0 firstLoop = true prevCount = 0 @tags.each do |tag, stats| if (firstLoop) prevCount = stats['count'] firstLoop = false end count = stats['count'] if (count < prevCount) changeCount += 1 if (changeCount == changes) break end end prevCount = stats['count'] unread = stats['unread'] puts sprintf "%-13s | %6d | %7d", tag, count, unread end end |
#printTopTable ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/tagStats.rb', line 174 def printTopTable puts sprintf "%-13s | %6s | %7s", 'tag', 'total', 'unread' puts '---------------------------------' top_count = 0 @tags.each do |tag, stats| count = stats['count'] unread = stats['unread'] puts sprintf "%-13s | %6d | %7d", tag, count, unread top_count += 1 if (top_count == 10) break end end end |