Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/dsl/monkeypatches.rb
Overview
Enchancement of String
class to generate random sample based on the pattern given.
Instance Method Summary collapse
-
#∀(size: 32, symbols: [*('A'..'Z'), *('а'..'я'), *('0'..'9'), *[' ']*10]) ⇒ String
(also: #any)
Generates random sample of
String
.
Instance Method Details
#∀(size: 32, symbols: [*('A'..'Z'), *('а'..'я'), *('0'..'9'), *[' ']*10]) ⇒ String Also known as: any
TODO:
Possible wanna use Faker here
Generates random sample of String
.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dsl/monkeypatches.rb', line 58 def ∀(size: 32, symbols: [*('A'..'Z'), *('а'..'я'), *('0'..'9'), *[' ']*10]) syms = case when !self.empty? then self.scan('.') when !(Array === symbols) && symbols.respond_to?(:to_a) then symbols.to_a else symbols end raise ArgumentError.new("`:symbols` argument class must support `#sample` method (given #{symbols})") \ unless syms.respond_to? :sample "".tap { |v| size.times { v << syms.sample } }.squeeze end |