Module: Hellodheena
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/hellodheena.rb
Constant Summary collapse
- @@grouped_result1 =
[]
Instance Method Summary collapse
- #to_hierarchy(result, group, c) ⇒ Object
- #to_initial(result, field) ⇒ Object
- #to_parent_calc(field) ⇒ Object
Instance Method Details
#to_hierarchy(result, group, c) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/hellodheena.rb', line 19 def to_hierarchy(result,group,c) if group[self.id].blank? self.attributes.merge({:level => c}) else self.attributes.merge({:level => c,:children => group[self.id].map{|x| x.to_hierarchy(result,group,c+1)}}) end end |
#to_initial(result, field) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/hellodheena.rb', line 3 def to_initial(result,field) @@grouped_result1 = result.group_by(&:parent_id) self.to_parent_calc(field) group = @@grouped_result1 self.to_hierarchy(result,group,1) end |
#to_parent_calc(field) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/hellodheena.rb', line 10 def to_parent_calc(field) unless @@grouped_result1[self.id].blank? @@grouped_result1[self.id].map{|x| x.to_parent_calc(field)} sum_value = @@grouped_result1[self.id].sum{|x| x[field].to_i} @@grouped_result1[self.parent_id].map{|x| x.id == self.id && x[field] = sum_value} end end |