Class: Stats::TagCloud

Inherits:
Object
  • Object
show all
Defined in:
app/models/stats/tag_cloud.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(tags)
  @levels = 10
  @tags = tags.sort_by { |tag| tag.name.downcase }
end

Instance Attribute Details

#levelsObject (readonly)

Returns the value of attribute levels.



5
6
7
# File 'app/models/stats/tag_cloud.rb', line 5

def levels
  @levels
end

#tagsObject (readonly)

Returns the value of attribute tags.



5
6
7
# File 'app/models/stats/tag_cloud.rb', line 5

def tags
  @tags
end

Instance Method Details

#countsObject (private)



34
35
36
# File 'app/models/stats/tag_cloud.rb', line 34

def counts
  @counts ||= tags.map(&:count)
end

#divisorObject (private)



30
31
32
# File 'app/models/stats/tag_cloud.rb', line 30

def divisor
  @divisor ||= ((max - min) / levels) + 1
end

#empty?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'app/models/stats/tag_cloud.rb', line 12

def empty?
  tags.empty?
end

#maxObject (private)



22
23
24
# File 'app/models/stats/tag_cloud.rb', line 22

def max
  @max ||= counts.max
end

#minObject (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