quickstrings 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/quickstrings/version.rb +3 -0
- data/lib/quickstrings.rb +99 -0
- data/quickstrings.gemspec +35 -0
- metadata +108 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 C4mz0r
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Quickstrings
|
2
|
+
|
3
|
+
Welcome to Quickstrings - a friendly little gem to help you generate useful strings on the fly when you're seeding your database with test data, or trying some experiements in IRB, etc. Quickstrings will help you generate the data you need with some simple function calls.
|
4
|
+
|
5
|
+
I've found that a lot of times when I'm making some seed data or messing about in IRB testing out some calls, I am typing in certain data, such as emails, urls, or maybe I need to specify an image. I've wasted countless keystrokes! So I've created this little gem to help simplify things, and I hope that it can help you out too!
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'quickstrings'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install quickstrings
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
This gem is fairly self-contained and doesn't have any dependencies.
|
26
|
+
|
27
|
+
Be sure to first require it in your code or IRB:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'quickstrings'
|
31
|
+
```
|
32
|
+
Then you can quickly generate the different types of strings you may need:
|
33
|
+
|
34
|
+
Examples:
|
35
|
+
```ruby
|
36
|
+
Quickstrings.email
|
37
|
+
Quickstrings.rstring(10)
|
38
|
+
|
39
|
+
# but if you don't like typing Quickstrings namespace out each time, you can shorten it
|
40
|
+
# e.g. QS=Quickstrings
|
41
|
+
|
42
|
+
QS=Quickstrings
|
43
|
+
QS.whitelist_string(whitelist, 10) # => Whitelist can be a 1-d array, range, fixnum, or string - and only those chars will be used in generating the string of specified length
|
44
|
+
QS.rstring # => Random a-z char
|
45
|
+
QS.rstring(10) # => Random a-z string of specified length
|
46
|
+
QS.rstring(10,'Q') # => Random a-z string of specified length, first and last letters are as specified. Useful when visually inspecting for string truncation, etc.
|
47
|
+
QS.rutf8string # => Random UTF-8 char (U+00C0 to U+00FF inclusive, except for U+00D7 and U+00F7)
|
48
|
+
QS.rutf8string(5) # => Random UTF-8 string of specified length
|
49
|
+
QS.email # => somebody@example.com
|
50
|
+
QS.remail # => Random email from a set
|
51
|
+
QS.url # => http://www.google.com
|
52
|
+
QS.rurl # => Random url from a set
|
53
|
+
QS.fname # => Frank
|
54
|
+
QS.rfname # => Random name from a set
|
55
|
+
QS.flname # => Frank Enstein (first and last name)
|
56
|
+
QS.rflname # => Random first and last name from a set
|
57
|
+
QS.image # => Link to the default gravatar 20x20 image
|
58
|
+
QS.image(500) # => Link to the default gravatar image with specified size (in this case 500x500 pixels)
|
59
|
+
QS.rimage # => Link to random gravatar image from a set
|
60
|
+
QS.rimage(500) # => Link to random gravatar image from a set with specified size
|
61
|
+
```
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
66
|
+
|
67
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/C4mz0r/quickstrings.
|
72
|
+
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
77
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "quickstrings"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/quickstrings.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require "quickstrings/version"
|
2
|
+
|
3
|
+
module Quickstrings
|
4
|
+
|
5
|
+
# Feel free to add items to the end of the arrays
|
6
|
+
# Specific functions are written to return the first thing in the array,
|
7
|
+
# so DO NOT add any new items in the first position of the arrays.
|
8
|
+
# Doing so will break tests and expected behavior.
|
9
|
+
URLS = ['http://www.google.com', 'http://www.amazon.com', 'http://www.linkedin.com']
|
10
|
+
EMAILS = ['somebody@example.com', 'somebody.else@example.com']
|
11
|
+
NAMES = ["Frank", "Mary", "Susan", "Apu"]
|
12
|
+
FULLNAMES = ["Frank Enstein", "Mary Contrary", "Susan Smith", "Apu Nahasapeemapetilon"]
|
13
|
+
|
14
|
+
# UTF8 sampling focus on umlauted characters from 00C0 to 00FF see http://www.utf8-chartable.de/
|
15
|
+
# Chars 00D7 and 00F7 would for some reason stop the next ones from generating, so they're excluded
|
16
|
+
UTF8SAMPLE = ("\u00C0".."\u00D6").to_a + ("\u00D8".."\u00F6").to_a + ("\u00F8".."\u00FF").to_a
|
17
|
+
|
18
|
+
IMAGES = ["http://www.gravatar.com/avatar/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", # default gravatar image
|
19
|
+
"http://www.gravatar.com/avatar/bebfcf57d6d8277d806a9ef3385c078d" # gravatar image from Hartl's book
|
20
|
+
]
|
21
|
+
|
22
|
+
|
23
|
+
def Quickstrings.url
|
24
|
+
URLS.first
|
25
|
+
end
|
26
|
+
|
27
|
+
def Quickstrings.rurl
|
28
|
+
URLS.sample
|
29
|
+
end
|
30
|
+
|
31
|
+
def Quickstrings.email
|
32
|
+
EMAILS.first
|
33
|
+
end
|
34
|
+
|
35
|
+
def Quickstrings.remail
|
36
|
+
EMAILS.sample
|
37
|
+
end
|
38
|
+
|
39
|
+
def Quickstrings.fname
|
40
|
+
NAMES.first
|
41
|
+
end
|
42
|
+
|
43
|
+
def Quickstrings.rfname
|
44
|
+
NAMES.sample
|
45
|
+
end
|
46
|
+
|
47
|
+
def Quickstrings.flname
|
48
|
+
FULLNAMES.first
|
49
|
+
end
|
50
|
+
|
51
|
+
def Quickstrings.rflname
|
52
|
+
FULLNAMES.sample
|
53
|
+
end
|
54
|
+
|
55
|
+
def Quickstrings.rutf8string(length = 1)
|
56
|
+
whitelist_string UTF8SAMPLE, length
|
57
|
+
end
|
58
|
+
|
59
|
+
def Quickstrings.image(size = nil)
|
60
|
+
IMAGES.first + (size.nil? ? "":"?s=#{size}")
|
61
|
+
end
|
62
|
+
|
63
|
+
def Quickstrings.rimage(size = nil)
|
64
|
+
IMAGES.sample + (size.nil? ? "":"?s=#{size}")
|
65
|
+
end
|
66
|
+
|
67
|
+
def Quickstrings.rstring(length = 1, delim = nil)
|
68
|
+
new_string = whitelist_string ('a'..'z'), length
|
69
|
+
if !delim.nil?
|
70
|
+
new_string[0] = delim
|
71
|
+
new_string[-1] = delim
|
72
|
+
end
|
73
|
+
new_string
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
def Quickstrings.whitelist_string(whitelist, length)
|
79
|
+
|
80
|
+
case(whitelist)
|
81
|
+
when Range
|
82
|
+
whitelist = whitelist.to_a
|
83
|
+
when String
|
84
|
+
whitelist = whitelist.split("")
|
85
|
+
when Fixnum
|
86
|
+
whitelist = whitelist.to_s.split("")
|
87
|
+
end
|
88
|
+
|
89
|
+
output = ""
|
90
|
+
|
91
|
+
length.times do
|
92
|
+
output += whitelist.sample
|
93
|
+
end
|
94
|
+
|
95
|
+
output
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'quickstrings/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "quickstrings"
|
8
|
+
spec.version = Quickstrings::VERSION
|
9
|
+
spec.authors = ["C4mz0r"]
|
10
|
+
spec.email = ["aut0x@hotmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generate different types of common strings quickly! Great for creating test data!}
|
13
|
+
spec.description = %q{Do you hate typing / copying strings all over the place when your working on your app? This gem will help you to create common strings quickly and easily.}
|
14
|
+
spec.homepage = "https://github.com/C4mz0r/quickstrings"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
=begin
|
18
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
19
|
+
# delete this section to allow pushing this gem to any host.
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
else
|
23
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
24
|
+
end
|
25
|
+
=end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quickstrings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- C4mz0r
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-10-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.10'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.10'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '10.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '10.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Do you hate typing / copying strings all over the place when your working
|
63
|
+
on your app? This gem will help you to create common strings quickly and easily.
|
64
|
+
email:
|
65
|
+
- aut0x@hotmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- .rspec
|
72
|
+
- .travis.yml
|
73
|
+
- Gemfile
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- bin/console
|
78
|
+
- bin/setup
|
79
|
+
- lib/quickstrings.rb
|
80
|
+
- lib/quickstrings/version.rb
|
81
|
+
- quickstrings.gemspec
|
82
|
+
homepage: https://github.com/C4mz0r/quickstrings
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.23
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Generate different types of common strings quickly! Great for creating test
|
107
|
+
data!
|
108
|
+
test_files: []
|