Class: Stats::TagCloud
- Inherits:
-
Object
- Object
- Stats::TagCloud
- Defined in:
- app/models/stats/tag_cloud.rb
Instance Attribute Summary collapse
-
#levels ⇒ Object
readonly
Returns the value of attribute levels.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #counts ⇒ Object private
- #divisor ⇒ Object private
- #empty? ⇒ Boolean
-
#initialize(tags) ⇒ TagCloud
constructor
A new instance of TagCloud.
- #max ⇒ Object private
- #min ⇒ Object private
- #relative_size(tag) ⇒ Object
Constructor Details
#initialize(tags) ⇒ TagCloud
Returns a new instance of TagCloud.
7 8 9 10 |
# File 'app/models/stats/tag_cloud.rb', line 7 def initialize() @levels = 10 = .sort_by { |tag| tag.name.downcase } end |
Instance Attribute Details
#levels ⇒ Object (readonly)
Returns the value of attribute levels.
5 6 7 |
# File 'app/models/stats/tag_cloud.rb', line 5 def levels @levels end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
5 6 7 |
# File 'app/models/stats/tag_cloud.rb', line 5 def end |
Instance Method Details
#counts ⇒ Object (private)
34 35 36 |
# File 'app/models/stats/tag_cloud.rb', line 34 def counts @counts ||= .map(&:count) end |
#divisor ⇒ Object (private)
30 31 32 |
# File 'app/models/stats/tag_cloud.rb', line 30 def divisor @divisor ||= ((max - min) / levels) + 1 end |
#empty? ⇒ Boolean
12 13 14 |
# File 'app/models/stats/tag_cloud.rb', line 12 def empty? .empty? end |
#max ⇒ Object (private)
22 23 24 |
# File 'app/models/stats/tag_cloud.rb', line 22 def max @max ||= counts.max end |
#min ⇒ Object (private)
26 27 28 |
# File 'app/models/stats/tag_cloud.rb', line 26 def min @min ||= counts.min end |
#relative_size(tag) ⇒ Object
16 17 18 |
# File 'app/models/stats/tag_cloud.rb', line 16 def relative_size(tag) (tag.count - min) / divisor end |