Class: Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tag
- Defined in:
- lib/tagger/tag.rb
Constant Summary collapse
- SEPARATORS =
{ :comma => ",", :space => " " }
Instance Attribute Summary collapse
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Class Method Summary collapse
-
.cloud(type, options = {}) ⇒ Object
Tag.cloud(:post) Tag.cloud(:post, :scope => @category) Tag.cloud(:post, :limit => 50).
-
.parse(tag_list, separator) ⇒ Object
Tag.parse(tags_list, :comma) Tag.parse(tags_list, :space).
Instance Method Summary collapse
Instance Attribute Details
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
8 9 10 |
# File 'lib/tagger/tag.rb', line 8 def weight @weight end |
Class Method Details
.cloud(type, options = {}) ⇒ Object
Tag.cloud(:post) Tag.cloud(:post, :scope => @category) Tag.cloud(:post, :limit => 50)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tagger/tag.rb', line 13 def self.cloud(type, = {}) [:limit] ||= 100 scope_condition = " AND scopable_type = #{[:scope].class.to_s.inspect} AND scopable_id = #{[:scope].id}" if [:scope] = Tag.find_by_sql [%( SELECT tags.id, tags.name, COUNT(*) AS total FROM tags, taggings WHERE tags.id == taggings.tag_id AND taggings.taggable_type = ? #{scope_condition} GROUP BY taggings.tag_id ORDER BY total DESC, name ASC LIMIT ? ), type.to_s.classify, [:limit]] end |
.parse(tag_list, separator) ⇒ Object
Tag.parse(tags_list, :comma) Tag.parse(tags_list, :space)
35 36 37 38 39 40 41 42 |
# File 'lib/tagger/tag.rb', line 35 def self.parse(tag_list, separator) separator = SEPARATORS[separator] || SEPARATORS[:comma] = [] tag_list = tag_list.dup tag_list.gsub!(/(["'])(.*?)(\1)/m) {|m| << $2; "" } += tag_list.split(separator) .collect(&:squish).reject(&:blank?).sort_by {|tag| tag.downcase} end |
Instance Method Details
#to_s ⇒ Object
48 49 50 |
# File 'lib/tagger/tag.rb', line 48 def to_s name end |
#total ⇒ Object
44 45 46 |
# File 'lib/tagger/tag.rb', line 44 def total read_attribute(:total).to_i end |