Sha256: d41a1bfe52c94af35f60a8aab0aa0f05b1f755787a5a930d4b574455b458829d
Contents?: true
Size: 1.68 KB
Versions: 2
Compression:
Stored size: 1.68 KB
Contents
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'fathom')) class Fathom::MCNode < Fathom::Node attr_reader :value_description, :samples_taken def initialize(opts={}, &block) super(opts) @value_description = opts[:value_description] @value_description ||= block if block_given? raise ArgumentError, "Must provide a value_description from either a parameter or by passing in a block" unless @value_description end def process(n=10_000) @samples_taken, @samples = n, {} @samples_taken.times do result = value_description.call(self) store(result) end assert_nodes end def reset! @samples_taken, @samples = nil, {} @samples_asserted = false end def fields self.children.map {|c| c.name_sym}.compact end protected def store(result) result = assert_result_hash(result) assert_samples(result) result.each do |key, value| @samples[key.to_sym] << value end end def assert_samples(result) return true if @samples_asserted result.each do |k, v| @samples[k.to_sym] ||= [] end @samples_asserted = true end def assert_result_hash(result) result.is_a?(Hash) ? result : {:result => result} end # Assumes the same value description for all samples taken def assert_nodes @samples.each do |key, values| node = DataNode.new(:name => key, :values => values) add_child(node) # self.class.define_summary_method(key) end end end if __FILE__ == $0 include Fathom # TODO: Is there anything you want to do to run this file on its own? # MCNode.new end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fathom-0.3.4 | lib/fathom/node/mc_node.rb |
fathom-0.3.3 | lib/fathom/node/mc_node.rb |