Parent

Benelux::Stats

Attributes

names[R]

Public Class Methods

new(*names) click to toggle source
# File lib/benelux/stats.rb, line 6
def initialize(*names)
  @names = []
  add_groups names
end

Public Instance Methods

+(other) click to toggle source
# File lib/benelux/stats.rb, line 49
def +(other)
  if !other.is_a?(Benelux::Stats)
    raise TypeError, "can't convert #{other.class} into Stats" 
  end
  s = self.clone
  other.names.each do |name|
    s.add_group name
    s.group(name) << other.group(name)
  end
  s
end
add_group(*args) click to toggle source
Alias for: add_groups
add_groups(*args) click to toggle source
# File lib/benelux/stats.rb, line 33
def add_groups(*args)
  args.flatten.each do |meth|
    next if has_group? meth
    @names << meth
    self.class.send :attr_reader, meth
    (g = Benelux::Stats::Group.new).name = meth
    instance_variable_set("@#{meth}", g)
  end
end
Also aliased as: add_group
clear() click to toggle source
# File lib/benelux/stats.rb, line 18
def clear
  each { |g| g.clear }
  @names.clear
end
create_zero_group(name) click to toggle source
# File lib/benelux/stats.rb, line 13
def create_zero_group(name)
  g = Benelux::Stats::Group.new
  g.name = name
  g
end
each(&blk) click to toggle source

Each group

# File lib/benelux/stats.rb, line 26
def each(&blk)
  @names.each { |name| blk.call(group(name)) }
end
each_pair(&blk) click to toggle source

Each group name, group

# File lib/benelux/stats.rb, line 30
def each_pair(&blk)
  @names.each { |name| blk.call(name, group(name)) }
end
group(name) click to toggle source
# File lib/benelux/stats.rb, line 10
def group(name)
  @names.member?(name) ? self.send(name) : create_zero_group(name)
end
has_group?(name) click to toggle source
# File lib/benelux/stats.rb, line 46
def has_group?(name)
  @names.member? name
end
sample(name, s, tags={}) click to toggle source
# File lib/benelux/stats.rb, line 42
def sample(name, s, tags={})
  self.send(name).sample(s, tags)
end
size() click to toggle source
# File lib/benelux/stats.rb, line 22
def size
  @names.size
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.