random_string 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ # uncomment this line if your project needs to run something other than `rake`:
6
+ script: bundle exec rspec spec
data/README.rdoc CHANGED
@@ -1,4 +1,6 @@
1
1
  = RandomString
2
+ {<img src="https://badge.fury.io/rb/random_string.png" alt="Gem Version" />}[http://badge.fury.io/rb/random_string]
3
+ {<img src="https://travis-ci.org/nqtien310/random_string.png?branch=master" alt="Build Status" />}[https://travis-ci.org/nqtien310/random_string]
2
4
 
3
5
  Ruby library which generates strings which match a regular expression
4
6
 
@@ -6,7 +6,7 @@ module RandomString
6
6
 
7
7
  def generate(pattern)
8
8
  matched_strings = []
9
- unmatched_strings = []
9
+ unmatched_strings = []
10
10
  sample_strings.each do |sample_string|
11
11
  break if matched_strings.size == ResultCount && unmatched_strings.size == ResultCount
12
12
 
@@ -10,24 +10,58 @@ module RandomString
10
10
 
11
11
  private
12
12
 
13
- def sample_strings
14
- (stored_strings + random_digits_strings + random_chars_strings).uniq.shuffle
13
+ def sample_strings
14
+ private_methods.select { |method| method =~ /_data$/ }.inject([]) do |all, method|
15
+ all << eval(method.to_s)
16
+ end.flatten.compact.uniq.shuffle
15
17
  end
16
18
 
17
- def stored_strings
18
- Data::StoredStrings.values.flatten
19
+ def stored_data
20
+ ( stored_strings + capitalize_stored_strings + dot_prefix_stored_strings ).flatten.uniq
19
21
  end
20
22
 
21
- def random_digits_strings
23
+ def random_digits_data
22
24
  random_strings(Digits)
23
25
  end
24
26
 
25
- def random_chars_strings
27
+ def random_chars_data
26
28
  random_strings(LowerCaseChars + UpperCaseChars)
27
29
  end
28
30
 
31
+ def percentages_data
32
+ (1..100).map { |n| "#{n}%"}
33
+ end
34
+
35
+ def digits_data
36
+ Digits
37
+ end
38
+
39
+ def lower_case_chars_data
40
+ LowerCaseChars
41
+ end
42
+
43
+ def upper_case_chars_data
44
+ UpperCaseChars
45
+ end
46
+
47
+ def floats_data
48
+ (0...1).step(0.01).to_a.map.each {|f| f.round(2).to_s}
49
+ end
50
+
51
+ def stored_strings
52
+ Data::StoredStrings.values.flatten
53
+ end
54
+
55
+ def capitalize_stored_strings
56
+ ( Data::CapitalStoredStrings.values + Data::CapitalStoredStrings.values.flatten.map(&:capitalize) ).flatten
57
+ end
58
+
59
+ def dot_prefix_stored_strings
60
+ ( Data::DotPrefixStoredStrings.values + Data::DotPrefixStoredStrings.values.flatten.map { |v| ".#{v}"} ).flatten
61
+ end
62
+
29
63
  def random_strings(base)
30
64
  (1..GenerateCount).map { |length| length.times.inject('') { |initial, n| initial + base[rand(base.size-1)].to_s } }
31
- end
65
+ end
32
66
  end
33
67
  end
@@ -6,26 +6,38 @@ module RandomString
6
6
  :Urls => ['www.domain.com', 'www.domain.subdomain.com', 'http://www.domain.com', 'http://www.domain.subdomain.com',
7
7
  'http://www.domain.com/path/1', 'https://www.domain.com', 'https://www.domain.subdomain.com', 'domain.subdomain.com',
8
8
  'domain.com/path/1', 'subdomain.domain.com/path/1'],
9
- :IPS => ['192.168.1.1', '192.168.1.2'],
10
- :Sex => ['male', 'female', 'gay', 'les', 'other'],
9
+ :IPS => ['192.168.1.1', '192.168.1.2'],
11
10
  :Zips => ['10001', '10002', '10003'],
12
- :Phones => ['732-757-2923', '1732-757-2923', '+84 121731845', '84 121731845', '(84) 121731845'],
13
- :Datetimes => ['1999-01-01', '99-01-01', '1999/01/01', '99/01/01', '01/01/99', '03/10/1986', '01-01-1999', '01-01-99', 'January 07, 2013',
14
- 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday',
15
- 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december',
16
- 'am', 'pm'],
17
- :Countries => ['Vietnam', 'America', 'England', 'Vietnamese', 'American', 'English'],
18
- :Cities => ['New York', 'London', 'Ho Chi Minh'],
19
- :Statuses => ['married', 'single', 'available', 'complicated'],
20
- :Files => ['filename.txt', 'filename.jpg', 'filename.png', 'filename.jpeg'],
21
- :Extensions => ['txt', 'jpg', 'png', 'jpeg', 'mp4', 'mp3', 'wmv'],
11
+ :Phones => ['732-757-2923', '1732-757-2923', '+84 121731845', '84 121731845', '(84) 121731845', '754-3010',
12
+ '(541) 754-3010', '+1-541-754-3010', '1-541-754-3010'],
13
+ :Datetimes => ['1999-01-01', '99-01-01', '1999/01/01', '99/01/01', '01/01/99', '03/10/1986', '01-01-1999', '01-01-99', 'January 07, 2013'],
14
+ :Files => ['filename.txt', 'filename.jpg', 'filename.png', 'filename.jpeg'],
22
15
  :Videos => ['filename.wmv', 'filename.mp4', 'filename.flv'],
23
16
  :CCNumbers => ['4111 1111 1111 1111', '5500 0000 0000 0004', '3400 0000 0000 009', '3000 0000 0000 04'],
24
17
  :CCodes => ['84', '1', '39'],
25
- :ISOCCodes => ['US', 'USA', 'VN', 'VNM'],
26
- :Services => ['yahoo', 'google', 'facebook', 'amazone', 'youtube', 'paypal', 'alchemy'],
18
+ :ISOCCodes => ['US', 'USA', 'VN', 'VNM']
19
+ }
20
+
21
+ DotPrefixStoredStrings = {
22
+ :Extensions => ['txt', 'jpg', 'png', 'jpeg', 'mp4', 'mp3', 'wmv', 'exe', 'dmg', 'jar', 'tar', 'zip', 'gif', 'pdf'],
23
+ :LanguageExts => ['java', 'rb', 'php', 'asp','html', 'xhtml', 'js', 'pl', 'py', 'xml', 'rss', 'css','cgi', 'dll', 'rss', 'markdown'],
24
+ :Domains => ['com', 'org', 'net', 'us', 'vn', 'edu', 'gov', 'biz', 'info', 'tv', 'uk']
25
+ }
26
+
27
+ CapitalStoredStrings = {
28
+ :Services => ['yahoo', 'google', 'facebook', 'amazone', 'youtube', 'paypal', 'alchemy', 'github',
29
+ 'rubygems', 'travis', 'open calais', 'engine yard', 'netflix', 'dropbox', 'flickr', 'pandora one',
30
+ 'evernote', 'xmarks', 'lastpass' ],
31
+ :Countries => ['Vietnam', 'America', 'England', 'Vietnamese', 'American', 'English'],
32
+ :Cities => ['New York', 'London', 'Ho Chi Minh'],
33
+ :Datestimes => ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday',
34
+ 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december',
35
+ 'am', 'pm'],
36
+ :Sex => ['male', 'female', 'gay', 'les', 'other'],
37
+ :Statuses => ['married', 'single', 'available', 'complicated'],
27
38
  :Marks => ['excellent', 'good', 'bad']
39
+
28
40
  }
29
41
  end
30
42
  end
31
- end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module RandomString
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -3,15 +3,15 @@ require 'spec_helper'
3
3
  describe "RandomString::SampleString" do
4
4
  include RandomString::SampleString
5
5
 
6
- describe "#stored_strings" do
6
+ describe "#stored_data" do
7
7
  it 'should return an array of string' do
8
- send(:stored_strings).should be_an Array
9
- send(:stored_strings).should_not be_empty
8
+ send(:stored_data).should be_an Array
9
+ send(:stored_data).should_not be_empty
10
10
  end
11
11
  end
12
12
 
13
13
  describe '#random_digits' do
14
- let(:random_digits) { send(:random_digits_strings) }
14
+ let(:random_digits) { send(:random_digits_data) }
15
15
 
16
16
  it 'should return array with maximum size config in SampleString::GenerateCount' do
17
17
  random_digits.size.should eq RandomString::SampleString::GenerateCount
@@ -23,7 +23,7 @@ describe "RandomString::SampleString" do
23
23
  end
24
24
 
25
25
  describe '#random_chars' do
26
- let(:random_chars) { send(:random_chars_strings) }
26
+ let(:random_chars) { send(:random_chars_data) }
27
27
 
28
28
  it 'should return array with maximum size config in SampleString::GenerateCount' do
29
29
  random_chars.size.should eq RandomString::SampleString::GenerateCount
@@ -34,14 +34,51 @@ describe "RandomString::SampleString" do
34
34
  end
35
35
  end
36
36
 
37
+ describe '#percentage_data' do
38
+ it 'should contain percentage numbers' do
39
+ pd = send(:percentages_data)
40
+ pd.size.should == 100
41
+ pd.should be_include("50%")
42
+ end
43
+ end
44
+
45
+ describe '#floats_data' do
46
+ it 'should contain float numbers from 0 to 1 step 0.01' do
47
+ pd = send(:floats_data)
48
+ pd.size.should == 100
49
+ pd.should be_include("0.99")
50
+ end
51
+ end
52
+
53
+ describe '#capitalize_stored_strings' do
54
+ it 'should contain both lower case and capitalize words' do
55
+ css = send(:capitalize_stored_strings)
56
+ css.should be_include('yahoo')
57
+ css.should be_include('Yahoo')
58
+ end
59
+ end
60
+
61
+ describe '#dot_prefix_stored_strings' do
62
+ it 'should contain both normal works words as extensions' do
63
+ dpss = send(:dot_prefix_stored_strings)
64
+ dpss.should be_include('rb')
65
+ dpss.should be_include('.rb')
66
+ end
67
+ end
68
+
37
69
  describe '#sample_strings' do
38
70
  before do
39
- should_receive(:random_chars_strings).once.and_return [1,2,3]
40
- should_receive(:random_digits_strings).once.and_return [4,5,6,6]
41
- should_receive(:stored_strings).once.and_return [7,8,9]
71
+ should_receive(:random_chars_data).once.and_return [1]
72
+ should_receive(:random_digits_data).once.and_return [2]
73
+ should_receive(:stored_data).once.and_return [3]
74
+ should_receive(:percentages_data).once.and_return(4)
75
+ should_receive(:floats_data).once.and_return(5)
76
+ should_receive(:digits_data).once.and_return(6)
77
+ should_receive(:lower_case_chars_data).once.and_return(7)
78
+ should_receive(:upper_case_chars_data).once.and_return([8,9])
42
79
  end
43
80
 
44
- it 'should return an unique array which is a combination of stored_strings, random_digits, random_chars' do
81
+ it 'should return an unique array which is a combination of stored_data, random_digits, random_chars' do
45
82
  send(:sample_strings).sort.should eq [1,2,3,4,5,6,7,8,9]
46
83
  end
47
84
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: random_string
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -54,6 +54,7 @@ files:
54
54
  - .rdebugrc
55
55
  - .rspec
56
56
  - .rvmrc
57
+ - .travis.yml
57
58
  - Gemfile
58
59
  - LICENSE.txt
59
60
  - README.rdoc