Class: TimeArray::GroupHash
- Inherits:
-
Hash
- Object
- Hash
- TimeArray::GroupHash
- Defined in:
- lib/time_array/group_hash.rb
Instance Method Summary collapse
Instance Method Details
#count(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/time_array/group_hash.rb', line 22 def count(={}) if [:values] raise ArgumentError, "Option not recognized" if !%w(positive negative non_positive non_negative non_zero zero all).include?([:values].to_s) each_pair{|k,v| self[k]=v.send("count_"+[:values])} else each_pair{|k,v| self[k]=v.count_all} end end |
#sum(options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/time_array/group_hash.rb', line 3 def sum(={}) if [:values] case [:values] when :positive, :non_negative each_pair{|k,v| self[k]=v.sum_positive} when :negative, :non_positive each_pair{|k,v| self[k]=v.sum_negative} when :zero each_pair{|k,v| self[k]=0.0} when :all, :non_zero each_pair{|k,v| self[k]=v.sum_all} else raise ArgumentError, "Option not recognized" end else each_pair{|k,v| self[k]=v.sum_all} end end |