Module: Mongoid::TaggableWithContext::AggregationStrategy::RealTimeGroupBy::ClassMethods
- Defined in:
- lib/mongoid/taggable_with_context/aggregation_strategy/real_time_group_by.rb
Instance Method Summary collapse
- #tag_name_attribute ⇒ Object
- #tags_for(context, group_by, conditions = {}) ⇒ Object
- #tags_with_weight_for(context, group_by, conditions = {}) ⇒ Object
Instance Method Details
#tag_name_attribute ⇒ Object
7 8 9 |
# File 'lib/mongoid/taggable_with_context/aggregation_strategy/real_time_group_by.rb', line 7 def tag_name_attribute "_name" end |
#tags_for(context, group_by, conditions = {}) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/mongoid/taggable_with_context/aggregation_strategy/real_time_group_by.rb', line 11 def (context, group_by, conditions={}) results = if group_by query(context, group_by).to_a.map{ |t| t[tag_name_attribute] } else super(context, conditions) end results.uniq end |
#tags_with_weight_for(context, group_by, conditions = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mongoid/taggable_with_context/aggregation_strategy/real_time_group_by.rb', line 20 def (context, group_by, conditions={}) results = if group_by query(context, group_by).to_a.map{ |t| [t[tag_name_attribute], t["value"].to_i] } else super(context, conditions) end tag_hash = {} results.each do |tag, weight| tag_hash[tag] ||= 0 tag_hash[tag] += weight end tag_hash.to_a end |