Module: Quick::Sampler::DSL::SimpleValues
- Included in:
- Quick::Sampler::DSL
- Defined in:
- lib/quick/sampler/dsl/simple_values.rb
Overview
Samplers of simple values to form the basis of the sampled data structure.
Note from the future
In the future simple values are sampled from other excellent Gems from behind a composable Quick Sampler API. In the mean time this is possible at the cost of readablity:
Instance Method Summary collapse
-
#boolean ⇒ Quick::Sampler<Boolean>
A sampler of
trueandfalsevalues. -
#const(const) ⇒ Quick::Sampler<Anything>
Degenerate constant sampler.
-
#fixnum ⇒ Quick::Sampler<Fixnum>
Samples random fixnums (smaller integers that can be handled quickly by the CPU itself).
-
#integer ⇒ Quick::Sampler<Fixnum>
A sampler of integers prefering smaller ones.
-
#negative_fixnum ⇒ Quick::Sampler<Fixnum>
(also: #negative_integer)
A sampler of negative fixnums.
-
#positive_fixnum ⇒ Quick::Sampler<Fixnum>
(also: #positive_integer)
A sampler of positive fixnums.
-
#string(*classes) ⇒ Object
This sampler honors
upper_boundconfig variable. -
#zero ⇒ Quick::Sampler<0>
Degenerate sampler of zeros.
Instance Method Details
#boolean ⇒ Quick::Sampler<Boolean>
Returns a sampler of true and false values.
74 75 76 |
# File 'lib/quick/sampler/dsl/simple_values.rb', line 74 def boolean pick_from([true, false]) end |
#const(const) ⇒ Quick::Sampler<Anything>
Degenerate constant sampler. Will probably be superseeded by a cleaner smarter syntax as I get a better hang of it.
24 25 26 |
# File 'lib/quick/sampler/dsl/simple_values.rb', line 24 def const const feed { const } end |
#fixnum ⇒ Quick::Sampler<Fixnum>
Samples random fixnums (smaller integers that can be handled quickly by the CPU itself)
43 44 45 |
# File 'lib/quick/sampler/dsl/simple_values.rb', line 43 def fixnum pick_from(FixnumRange) end |
#integer ⇒ Quick::Sampler<Fixnum>
A sampler of integers prefering smaller ones
It will however sample a large one (from the Fixnum range) occasionally.
62 63 64 65 66 67 68 |
# File 'lib/quick/sampler/dsl/simple_values.rb', line 62 def integer one_of_weighted(fixnum => 5, pick_from(-1_000_000_000..1_000_000_000) => 7, pick_from(-1000..1000) => 9, pick_from(-100..100) => 11, pick_from(-20..20) => 17) end |
#negative_fixnum ⇒ Quick::Sampler<Fixnum> Also known as: negative_integer
Returns a sampler of negative fixnums.
48 49 50 |
# File 'lib/quick/sampler/dsl/simple_values.rb', line 48 def negative_fixnum pick_from(FixnumRange.min..-1) end |
#positive_fixnum ⇒ Quick::Sampler<Fixnum> Also known as: positive_integer
Returns a sampler of positive fixnums.
53 54 55 |
# File 'lib/quick/sampler/dsl/simple_values.rb', line 53 def positive_fixnum pick_from(1..FixnumRange.max) end |
#string(*classes) ⇒ Object
document character classes
This sampler honors upper_bound config variable.
The sampler will produce strings of random (between 0 and upper_bound) length
made up of characters belonging to supplied named classes.
87 88 89 90 91 |
# File 'lib/quick/sampler/dsl/simple_values.rb', line 87 def string *classes classes = [:printable] if classes.empty? repertoire = DSL::CharacterClass.(*classes) feed { repertoire.sample(rand(upper_bound)).join } end |
#zero ⇒ Quick::Sampler<0>
Degenerate sampler of zeros. Like #const this will probably go away soon.
32 33 34 |
# File 'lib/quick/sampler/dsl/simple_values.rb', line 32 def zero const 0 end |