module StatVal

Constants

VERSION

Public Class Methods

all_keys() click to toggle source
# File lib/statval/statval.rb, line 174
def self.all_keys ; [ :avg, :std, :std_ratio, :min, :max, :num, :sum, :sq_sum, :avg_sq, :var ] end
default_keys() click to toggle source
# File lib/statval/statval.rb, line 175
def self.default_keys ; [ :avg, :std, :min, :max, :num ] end
flatmap_hash(h, which_keys = nil, prefix=true, use_symbols=false) click to toggle source

Like map_hash, but flattens converted StatVal values such there attributes get pre- or appended with their key in the outer hash

All symbols raises on key conflict

# File lib/statval/statval.rb, line 212
def self.flatmap_hash(h, which_keys = nil, prefix=true, use_symbols=false)
  return h.to_hash(which_keys, ! use_symbols) if h.kind_of?(StatVal)

  flat = {}
  h.each_pair do |k,r|
    if r.kind_of? StatVal
      results = r.to_hash(which_keys)
      results.each_pair do |tag,val|
        new_tag = if prefix then "#{tag}_#{k}" else "#{k}_#{tag}" end
        new_tag = new_tag.to_sym if use_symbols

        raise ArgumentError if flat[new_tag]
        flat[new_tag] = val
      end
    else
      raise ArgumentError if flat[k]
      if k.is_a?(Symbol) && !use_symbols
        flat[k.to_s] = r
      else
        flat[k] = r
      end
    end
  end
  flat
end
key_hash(which_keys = nil) click to toggle source
# File lib/statval/statval.rb, line 190
def self.key_hash(which_keys = nil)
  return which_keys if which_keys.is_a?(Hash)
  keys(which_keys).inject({}) { |h, k| h[k] = k; h }
end
keys(ident = :default) click to toggle source
# File lib/statval/statval.rb, line 178
def self.keys(ident = :default)
  case ident
  when :all then all_keys
  when :writable then writable_keys
  when :default then default_keys
  when nil then default_keys
  else
    return ident if ident.respond_to?(:each)
    return [ident]
  end
end
map_hash(h, which_keys = nil) click to toggle source

Take hash that contains StatVal values and create new hash that is identical to it but has the StatVal values v replaced by v.to_hash(which_keys)

Just copies non-StatVal entries

# File lib/statval/statval.rb, line 200
def self.map_hash(h, which_keys = nil)
  r = {}
  h.each_pair { |k,v| r[k] = if v.kind_of?(StatVal) then v.to_hash(which_keys) else v end }
  r
end
new(options = {}) click to toggle source
# File lib/statval/statval.rb, line 172
def self.new(options = {}) ; StatVal.new(options) end
writable_keys() click to toggle source
# File lib/statval/statval.rb, line 176
def self.writable_keys ; [ :num, :min, :max, :sum, :sq_sum ] end