Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/conductor.rb
Instance Method Summary collapse
Instance Method Details
#sum_it(attribute) ⇒ Object
90 91 92 |
# File 'lib/conductor.rb', line 90 def sum_it(attribute) self.map {|x| x.send(attribute) }.compact.sum end |
#weighted_mean ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/conductor.rb', line 98 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
94 95 96 |
# File 'lib/conductor.rb', line 94 def weighted_mean_of_attribute(attribute) self.map {|x| x.send(attribute) }.compact.weighted_mean end |