Module: Regtest
- Defined in:
- lib/regtest.rb
Class Attribute Summary collapse
-
.count ⇒ Object
Returns the value of attribute count.
-
.results ⇒ Object
Returns the value of attribute results.
-
.start ⇒ Object
Returns the value of attribute start.
Class Method Summary collapse
-
.combinations(hashy) ⇒ Object
Build all combinations of a Hash-like object with arrays as values.
- .sample(name) ⇒ Object
Class Attribute Details
.count ⇒ Object
Returns the value of attribute count.
62 63 64 |
# File 'lib/regtest.rb', line 62 def count @count end |
.results ⇒ Object
Returns the value of attribute results.
62 63 64 |
# File 'lib/regtest.rb', line 62 def results @results end |
.start ⇒ Object
Returns the value of attribute start.
62 63 64 |
# File 'lib/regtest.rb', line 62 def start @start end |
Class Method Details
.combinations(hashy) ⇒ Object
Build all combinations of a Hash-like object with arrays as values. Return value is an array of OpenStruct instances.
Example:
require 'ostruct'
o = OpenStruct.new
o.a = [1,2,3]
o.b = [:x, :y]
Regtest.combinations(o).map(&:to_h) # => [{:a=>1, :b=>:x}, {:a=>1, :b=>:y}, {:a=>2, :b=>:x}, {:a=>2, :b=>:y}, {:a=>3, :b=>:x}, {:a=>3, :b=>:y}]
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/regtest.rb', line 47 def combinations hashy h = hashy.to_h a = h[h.keys[0]].product(*h.values[1..-1]) res = [] a.each do |e| o = OpenStruct.new h.keys.zip(e) do |k, v| o[k] = v end res << o end res end |
.sample(name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/regtest.rb', line 17 def sample name h = {} name = name.to_s if name.kind_of?(Symbol) h['sample'] = name begin h['result'] = yield rescue Exception => e h['exception'] = e. end output_filename = caller.first.split(/:/).first.sub(/\.rb/, '') << '.yml' unless Regtest.results[output_filename] puts unless Regtest.results.empty? puts File.basename(output_filename, '.yml') Regtest.results[output_filename] = [] end Regtest.results[output_filename] << h Regtest.count += 1 print '.'; $stdout.flush end |