random_strings 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c0d1ad92e7ed98763a62731c44387edcb972428
4
+ data.tar.gz: fca5170d95bdfaaf7e540a6b1567cc92e563555f
5
+ SHA512:
6
+ metadata.gz: 83f23af5834fbfee952cb535b0af8419900a23d9abf4f8ca6a81ad435f42bfc37e8f24bf3ac41538874e828ba209bf2d4675d5d4100b6fde46d09c7946355f2a
7
+ data.tar.gz: 29bcfbcb488bd291d910767961ffc7256de83c9c605f5451785b70b2a953b405f417202838a8b293e4184da96d2c9422833ac6acd5ceb30b2f839390c6371663
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in random_strings.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sameer Siruguri
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # RandomStrings
2
+
3
+ This gem helps you generate random string of various "types" - a random email, a random date, a random Twitter handle, etc. Or just a random string.
4
+
5
+ It's a great gem to use when creating seeds for database applications - like in a Rails seeds.rb file, for example. (hint, hint.)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'random_strings'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install random_strings
20
+
21
+ ## Usage
22
+
23
+ Initialize like this:
24
+ @my_gen = RandomStrings::Generator.new do |config|
25
+ config.default_string_length=7
26
+ config.default_number_length=6
27
+ config.tld_list=['.net', '.my', '.ly']
28
+ end
29
+
30
+ Here are a few functions you can use:
31
+
32
+ @generator=RandomStrings::Generator.new
33
+ a_zip=@generator.random_zip # Will look like, 40072
34
+ an_email=@generator.random_email # Will look, uuyhWAAJne@uuqVGjEaka.net
35
+
36
+ These are composed from the following basic functions:
37
+
38
+ RandomStrings::Generator#random_digits
39
+ RandomStrings::Generator#random_string
40
+
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # Run the Rakefile in the root of the gem (where the gemspec is)
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.test_files = FileList['test/**/*.rb']
8
+ end
9
+
10
+ task :default => [:test]
11
+ task :release => [:build, :install]
@@ -0,0 +1,60 @@
1
+ require "random_strings/version"
2
+
3
+ module RandomStrings
4
+ class Config
5
+ def initialize(*args)
6
+ args.each do |method_name|
7
+ self.class.class_exec do
8
+
9
+ define_method("#{method_name}") do
10
+ eval "@#{method_name}"
11
+ end
12
+ define_method("#{method_name}=") do |inp|
13
+ eval "@#{method_name}=inp"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ class Generator
21
+ def initialize(&block)
22
+ @config=Config.new(:tld_list, :default_string_length, :default_number_length)
23
+ @config.tld_list=['.com', '.org', '.net']
24
+ @config.default_string_length=10
25
+ @config.default_number_length=5
26
+
27
+ if block
28
+ block.call @config
29
+ end
30
+ end
31
+
32
+ def random_digits(count=-1)
33
+ if count == -1
34
+ count = @config.default_number_length
35
+ end
36
+ selection = Range.new('0', '9').to_a
37
+ count.times.map { selection[Random.rand()*selection.size] }.join ""
38
+ end
39
+
40
+ def random_string(count=-1)
41
+ if count == -1
42
+ count = @config.default_string_length
43
+ end
44
+ selection = (Range.new('a', 'z').to_a | Range.new('A', 'Z').to_a)
45
+ count.times.map { selection[Random.rand()*selection.size] }.join ""
46
+ end
47
+
48
+ def random_array_element(arr)
49
+ arr[Random.rand*arr.size]
50
+ end
51
+
52
+ def random_email
53
+ random_string + '@' + random_string + random_array_element(@config.tld_list)
54
+ end
55
+
56
+ def random_zip
57
+ return random_digits 5
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module RandomStrings
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'random_strings/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "random_strings"
8
+ spec.version = RandomStrings::VERSION
9
+ spec.authors = ["Sameer Siruguri"]
10
+ spec.email = ["sameers.public@gmail.com"]
11
+ spec.description = %q{This gem helps you generate random string of various "types" - a random email, a random date, a random Twitter handle, etc. Or just a random string.}
12
+ spec.summary = %q{Do it like this: RandomString::Generator.new.random_email -> boom, you got y7nnha8@uioop.com! Most of the formats follow the Principle Of Least Surprise. Like, an email won't look like 7*6=42@hitchhiker.galaxy}
13
+ spec.homepage = "http://github.com/siruguri/random_strings"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'minitest'
24
+ end
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ gem 'minitest'
3
+
4
+ require_relative "../lib/random_strings"
5
+ require "minitest/autorun"
6
+
7
+ describe RandomStrings do
8
+
9
+ before do
10
+ @default_generator=RandomStrings::Generator.new
11
+ end
12
+
13
+
14
+ describe "when initializing" do
15
+ it "must correctly accept a config" do
16
+ @generate=(RandomStrings::Generator.new do |config|
17
+ config.tld_list=['.nettld']
18
+ end)
19
+
20
+ email = @generate.random_email
21
+
22
+ (/.nettld$/).match(email).wont_be_nil
23
+ end
24
+ end
25
+
26
+ describe "when getting a zip" do
27
+ it "must be a five digit number" do
28
+ zip=@default_generator.random_zip
29
+ (/\d{5}/.match(zip)).wont_be_nil
30
+ end
31
+ end
32
+
33
+ describe "you can get a random email" do
34
+ it "must be a reasonable email" do
35
+ email = @default_generator.random_email
36
+ (/[a-zA-Z0-9]+\@[a-zA-Z0-9]+\.(com|org|net)/.match(email)).wont_be_nil
37
+ end
38
+ end
39
+
40
+ describe "when generating random string" do
41
+ it "has a default length of 10" do
42
+ str = @default_generator.random_string
43
+ str.size.must_equal 10
44
+ end
45
+
46
+ it "can have a set length when initialized" do
47
+ @set_gen=(RandomStrings::Generator.new do |config|
48
+ config.default_string_length=42
49
+ end)
50
+
51
+ str=@set_gen.random_string
52
+ str.size.must_equal 42
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: random_strings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sameer Siruguri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: This gem helps you generate random string of various "types" - a random
56
+ email, a random date, a random Twitter handle, etc. Or just a random string.
57
+ email:
58
+ - sameers.public@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .travis.yml
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/random_strings.rb
70
+ - lib/random_strings/version.rb
71
+ - random_strings.gemspec
72
+ - test/tc_random_strings.rb
73
+ homepage: http://github.com/siruguri/random_strings
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.1.11
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: 'Do it like this: RandomString::Generator.new.random_email -> boom, you got
97
+ y7nnha8@uioop.com! Most of the formats follow the Principle Of Least Surprise. Like,
98
+ an email won''t look like 7*6=42@hitchhiker.galaxy'
99
+ test_files:
100
+ - test/tc_random_strings.rb