Module: RandomString::Main

Includes:
SampleString
Included in:
RandomString
Defined in:
lib/random_string/main.rb

Constant Summary

Constants included from SampleString

SampleString::Digits, SampleString::GenerateCount, SampleString::LowerCaseChars, SampleString::ResultCount, SampleString::UpperCaseChars

Instance Method Summary collapse

Instance Method Details

#generate(pattern) ⇒ Object Also known as: gen



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/random_string/main.rb', line 7

def generate(pattern)
	matched_strings = []
	unmatched_strings = []
	sample_strings.each do |sample_string|
		break if matched_strings.size == ResultCount && unmatched_strings.size == ResultCount

		if sample_string =~ pattern
			matched_strings << sample_string if matched_strings.size < ResultCount
		else
			unmatched_strings << sample_string if unmatched_strings.size < ResultCount
		end
	end

	{
		:matched_strings   => matched_strings,
		:unmatched_strings => unmatched_strings
	}
end