Class: Benelux::Stats::Group
- Inherits:
-
Array
- Object
- Array
- Benelux::Stats::Group
- Defined in:
- lib/benelux/stats.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #[](*tags) ⇒ Object (also: #filter)
-
#initialize(name) ⇒ Group
constructor
A new instance of Group.
- #max ⇒ Object
- #mean ⇒ Object
- #merge(*tags) ⇒ Object
- #min ⇒ Object
- #n ⇒ Object
- #sample(s, tags = {}) ⇒ Object
- #sd ⇒ Object
Constructor Details
#initialize(name) ⇒ Group
Returns a new instance of Group.
47 48 49 |
# File 'lib/benelux/stats.rb', line 47 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
46 47 48 |
# File 'lib/benelux/stats.rb', line 46 def name @name end |
Instance Method Details
#+(other) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/benelux/stats.rb', line 51 def +(other) unless @name == other.name raise BeneluxError, "Cannot add #{other.name} to #{@name}" end other.each do |newcalc| calcs = self.select { |calc| calc. == newcalc. } self << newcalc and next if calcs.empty? # This should only ever contain one b/c we should # not have several calculators with the same tags. calcs.each do |calc| calc += newcalc end end self end |
#[](*tags) ⇒ Object Also known as: filter
96 97 98 99 100 101 102 |
# File 'lib/benelux/stats.rb', line 96 def [](*) = Benelux::TagHelpers.normalize g = Benelux::Stats::Group.new @name g << self.select { |c| c. >= } g.flatten!(1) # only 1 level deep g end |
#max ⇒ Object
81 |
# File 'lib/benelux/stats.rb', line 81 def max() merge.max end |
#mean ⇒ Object
79 |
# File 'lib/benelux/stats.rb', line 79 def mean() merge.mean end |
#merge(*tags) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/benelux/stats.rb', line 85 def merge(*) = Benelux::TagHelpers.normalize mc = Calculator.new all = .empty? ? self : self.filter() all.each { |calc| mc.samples calc mc. calc. } mc end |
#min ⇒ Object
80 |
# File 'lib/benelux/stats.rb', line 80 def min() merge.min end |
#n ⇒ Object
83 |
# File 'lib/benelux/stats.rb', line 83 def n() merge.n end |
#sample(s, tags = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/benelux/stats.rb', line 67 def sample(s, ={}) raise BeneluxError, "tags must be a Hash" unless .kind_of?(Hash) calcs = self.select { |c| c. == } if calcs.empty? (c = Calculator.new). self << c calcs = [c] end calcs.each { |c| c.sample(s) } nil end |
#sd ⇒ Object
82 |
# File 'lib/benelux/stats.rb', line 82 def sd() merge.sd end |