Methods
public class
public instance
Attributes
names | [R] |
Public class methods
new
(*names)
[show source]
# File lib/benelux/stats.rb, line 6 6: def initialize(*names) 7: @names = [] 8: add_groups names 9: end
Public instance methods
+
(other)
[show source]
# File lib/benelux/stats.rb, line 49 49: def +(other) 50: if !other.is_a?(Benelux::Stats) 51: raise TypeError, "can't convert #{other.class} into Stats" 52: end 53: s = self.clone 54: other.names.each do |name| 55: s.add_group name 56: s.group(name) << other.group(name) 57: end 58: s 59: end
add_groups
(*args)
[show source]
# File lib/benelux/stats.rb, line 33 33: def add_groups(*args) 34: args.flatten.each do |meth| 35: next if has_group? meth 36: @names << meth 37: self.class.send :attr_reader, meth 38: (g = Benelux::Stats::Group.new).name = meth 39: instance_variable_set("@#{meth}", g) 40: end 41: end
clear
()
[show source]
# File lib/benelux/stats.rb, line 18 18: def clear 19: each { |g| g.clear } 20: @names.clear 21: end
create_zero_group
(name)
[show source]
# File lib/benelux/stats.rb, line 13 13: def create_zero_group(name) 14: g = Benelux::Stats::Group.new 15: g.name = name 16: g 17: end
each
(&blk)
Each group
[show source]
# File lib/benelux/stats.rb, line 26 26: def each(&blk) 27: @names.each { |name| blk.call(group(name)) } 28: end
each_pair
(&blk)
Each group name, group
[show source]
# File lib/benelux/stats.rb, line 30 30: def each_pair(&blk) 31: @names.each { |name| blk.call(name, group(name)) } 32: end
group
(name)
[show source]
# File lib/benelux/stats.rb, line 10 10: def group(name) 11: @names.member?(name) ? self.send(name) : create_zero_group(name) 12: end
has_group?
(name)
[show source]
# File lib/benelux/stats.rb, line 46 46: def has_group?(name) 47: @names.member? name 48: end
sample
(name, s, tags={})
[show source]
# File lib/benelux/stats.rb, line 42 42: def sample(name, s, tags={}) 43: self.send(name).sample(s, tags) 44: end