Module: ActsAsMongoTaggable::InstanceMethods
- Defined in:
- lib/acts_as_mongo_taggable.rb
Instance Method Summary collapse
- #_tags ⇒ Object
- #delete_all_tags ⇒ Object
- #model_tag(phrase, opts = {}) ⇒ Object
- #tag_ids ⇒ Object
- #tag_words_by_user(user) ⇒ Object
-
#tags(limit = nil) ⇒ Object
returns only the tag words, sorted by frequency; optionally can be limited.
- #tags_by_user(user) ⇒ Object
-
#tags_with_counts ⇒ Object
returns array of tags and counts: [[“matt”, 3], [“bob”, 2], [“bill”, 1], [“joe”, 1], [“frank”, 1]].
-
#tags_with_user_ids ⇒ Object
returns an array of ids and user_ids.
Instance Method Details
#_tags ⇒ Object
53 54 55 |
# File 'lib/acts_as_mongo_taggable.rb', line 53 def Tag.find(:all, tag_ids) end |
#delete_all_tags ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/acts_as_mongo_taggable.rb', line 44 def Tag.find(tag_ids).each do |tag| model_taggings = tag.taggings.select{|tagging| tagging.taggable_type == self.class.name && tagging.taggable_id == self.id} model_taggings.each{|tagging| tag.taggings.delete tagging} tag.save_or_destroy end update_attributes({ :model_tags => [], :tag_words => [] }) end |
#model_tag(phrase, opts = {}) ⇒ Object
87 88 89 90 |
# File 'lib/acts_as_mongo_taggable.rb', line 87 def model_tag(phrase, opts = {}) phrase = phrase.downcase unless opts[:case_sensitive] .detect{|tag| tag.word == phrase} end |
#tag_ids ⇒ Object
92 93 94 |
# File 'lib/acts_as_mongo_taggable.rb', line 92 def tag_ids .map(&:tag_id) end |
#tag_words_by_user(user) ⇒ Object
72 73 74 |
# File 'lib/acts_as_mongo_taggable.rb', line 72 def tag_words_by_user(user) (user).map(&:word) end |
#tags(limit = nil) ⇒ Object
returns only the tag words, sorted by frequency; optionally can be limited
81 82 83 84 85 |
# File 'lib/acts_as_mongo_taggable.rb', line 81 def (limit=nil) array = limit ||= array.size array[0,limit].map{|t| t[0]} end |
#tags_by_user(user) ⇒ Object
76 77 78 |
# File 'lib/acts_as_mongo_taggable.rb', line 76 def (user) .select{|tag| tag.user_ids.include? user.id} end |
#tags_with_counts ⇒ Object
returns array of tags and counts:
[["matt", 3], ["bob", 2], ["bill", 1], ["joe", 1], ["frank", 1]]
59 60 61 62 |
# File 'lib/acts_as_mongo_taggable.rb', line 59 def counts = .map{|tag| [tag.word, tag.tagging_count]} counts.sort{|a, b| b[1] <=> a[1]} end |
#tags_with_user_ids ⇒ Object
returns an array of ids and user_ids
65 66 67 68 69 70 |
# File 'lib/acts_as_mongo_taggable.rb', line 65 def .inject([]) do |arr, tag| tag.user_ids.each{|user_id| arr << [tag.id, user_id]} arr end end |