Class: Benelux::Stats::Group

Inherits:
Array
  • Object
show all
Includes:
Selectable
Defined in:
lib/benelux/stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Selectable

#filter!, included, normalize, #rfilter

Instance Attribute Details

#nameObject

Returns the value of attribute name.



64
65
66
# File 'lib/benelux/stats.rb', line 64

def name
  @name
end

Instance Method Details

#+(other) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/benelux/stats.rb', line 66

def +(other)
  unless @name == other.name
    raise BeneluxError, "Cannot add #{other.name} to #{@name}"
  end
  g = Group.new self
  g.name = @name
  g << other
  g
end

#<<(other) ⇒ Object



76
77
78
79
# File 'lib/benelux/stats.rb', line 76

def <<(other)
  self.push *other
  self
end

#filter(*tags) ⇒ Object Also known as: []



116
117
118
119
# File 'lib/benelux/stats.rb', line 116

def filter(*tags)
  (f = super).name = @name
  f
end

#maxObject



110
# File 'lib/benelux/stats.rb', line 110

def max()     merge.max    end

#meanObject



108
# File 'lib/benelux/stats.rb', line 108

def mean()    merge.mean   end

#merge(*tags) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/benelux/stats.rb', line 81

def merge(*tags)
  #tags = Selectable.normalize tags
  mc = Calculator.new
  mc.init_tags!
  all = tags.empty? ? self : self.filter(tags)
  all.each { |calc| 
    mc.merge! calc
    mc.add_tags_quick calc.tags
  }    
  mc
end

#minObject



109
# File 'lib/benelux/stats.rb', line 109

def min()     merge.min    end

#nObject



114
# File 'lib/benelux/stats.rb', line 114

def n()       merge.n      end

#sample(s, tags = {}) ⇒ Object

Raises:



93
94
95
96
97
98
99
100
# File 'lib/benelux/stats.rb', line 93

def sample(s, tags={})
  raise BeneluxError, "tags must be a Hash" unless Hash === tags
  c = Calculator.new
  c.add_tags tags
  c.sample s
  self << c
  nil
end

#sdObject



113
# File 'lib/benelux/stats.rb', line 113

def sd()      merge.sd     end

#sumObject



112
# File 'lib/benelux/stats.rb', line 112

def sum()     merge.sum    end

#sumsqObject



111
# File 'lib/benelux/stats.rb', line 111

def sumsq()   merge.sumsq  end

#tag_values(tag) ⇒ Object



102
103
104
105
# File 'lib/benelux/stats.rb', line 102

def tag_values(tag)
  vals = self.collect { |calc| calc.tags[tag] }
  Array.new vals.uniq
end

#tagsObject



107
# File 'lib/benelux/stats.rb', line 107

def tags()    merge.tags   end