Module: Mongoid::TaggableWithContext::GroupBy::AggregationStrategy::RealTime::ClassMethods
- Defined in:
- lib/mongoid/taggable_with_context/group_by/aggregation_strategy/real_time.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
8 9 10 |
# File 'lib/mongoid/taggable_with_context/group_by/aggregation_strategy/real_time.rb', line 8 def tag_name_attribute "_name" end |
#tags_for(context, group_by, conditions = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/mongoid/taggable_with_context/group_by/aggregation_strategy/real_time.rb', line 12 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mongoid/taggable_with_context/group_by/aggregation_strategy/real_time.rb', line 21 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 |