Class: String
- Defined in:
- lib/propr/random/string.rb,
lib/propr/shrink/string.rb
Defined Under Namespace
Modules: Characters
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.random(options = {}, m = Propr::Random) ⇒ String
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/propr/random/string.rb', line 29 def random( = {}, m = Propr::Random) min = [:min] || 0 max = [:max] || 10 = Hash[center: min].merge() charset = Characters.of(.fetch(:charset, :print)) m.bind(Integer.random(.merge(min: min, max: max))) do |size| m.bind(m.sequence(size.times.map { charset.random })) do |chars| m.unit(chars.join) end end end |
Instance Method Details
#shrink ⇒ Array<String>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/propr/shrink/string.rb', line 3 def shrink case size when 0 then [] when 1 shrunken = [] shrunken << downcase if self =~ /[[:upper:]]/ shrunken << " " if self =~ /(?! )\s/ shrunken << "a" if self =~ /[b-z]/ shrunken << "A" if self =~ /[B-Z]/ shrunken << "0" if self =~ /[1-9]/ shrunken << "" shrunken else split(//).shrink.map(&:join) end end |