Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/conductor.rb
Instance Method Summary collapse
Instance Method Details
#sum_it(attribute) ⇒ Object
77 78 79 |
# File 'lib/conductor.rb', line 77 def sum_it(attribute) self.map {|x| x.send(attribute) }.compact.sum end |
#weighted_mean ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/conductor.rb', line 85 def weighted_mean w_sum = sum(self) return 0.00 if w_sum == 0.00 w_prod = 0 self.each_index {|i| w_prod += (i+1) * self[i].to_f} w_prod.to_f / w_sum.to_f end |
#weighted_mean_of_attribute(attribute) ⇒ Object
81 82 83 |
# File 'lib/conductor.rb', line 81 def weighted_mean_of_attribute(attribute) self.map {|x| x.send(attribute) }.compact.weighted_mean end |