Module: ActsAsMongoTaggable::ClassMethods
- Defined in:
- lib/acts_as_mongo_taggable.rb
Instance Method Summary collapse
- #all_tags_with_counts ⇒ Object
- #all_with_tag(phrase, opts = {}) ⇒ Object
-
#first_with_tag(phrase, opts = {}) ⇒ Object
returns the first widget with this tag, a la ActiveRecord find() note: case-insensitive unless you specify otherwise with :case_sensitive=>true.
- #most_tagged_with(phrase, opts = {}) ⇒ Object
- #top_25_tags ⇒ Object
Instance Method Details
#all_tags_with_counts ⇒ Object
3 4 5 |
# File 'lib/acts_as_mongo_taggable.rb', line 3 def Tag.most_tagged(self).map{|tag| [tag.word, tag.count_for(self)]} end |
#all_with_tag(phrase, opts = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/acts_as_mongo_taggable.rb', line 17 def all_with_tag(phrase, opts={}) lo = opts.clone case_sensitive = lo.delete :case_sensitive phrase = phrase.downcase unless case_sensitive all(lo.merge(:tag_words => phrase)) end |
#first_with_tag(phrase, opts = {}) ⇒ Object
returns the first widget with this tag, a la ActiveRecord find() note: case-insensitive unless you specify otherwise with :case_sensitive=>true
9 10 11 12 13 14 |
# File 'lib/acts_as_mongo_taggable.rb', line 9 def first_with_tag(phrase, opts={}) lo = opts.clone case_sensitive = lo.delete :case_sensitive phrase = phrase.downcase unless case_sensitive first(lo.merge(:tag_words => phrase)) end |
#most_tagged_with(phrase, opts = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/acts_as_mongo_taggable.rb', line 24 def most_tagged_with(phrase, opts={}) lo = opts.clone case_sensitive = lo.delete :case_sensitive phrase = phrase.downcase unless case_sensitive #Doesn't work :( #first(lo.merge('model_tags.word' => phrase, :order => 'model_tags.tagging_count desc')) all_with_tag(phrase, lo).sort do |a, b| b.model_tag(phrase, opts).tagging_count <=> a.model_tag(phrase, opts).tagging_count end.first end |