├── .rspec ├── lib ├── quickstrings │ └── version.rb └── quickstrings.rb ├── .travis.yml ├── spec ├── spec_helper.rb └── quickstrings_spec.rb ├── Gemfile ├── .gitignore ├── Rakefile ├── bin ├── setup └── console ├── LICENSE.txt ├── quickstrings.gemspec └── README.md /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /lib/quickstrings/version.rb: -------------------------------------------------------------------------------- 1 | module Quickstrings 2 | VERSION = "0.1.1" 3 | end 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 1.9.3 4 | before_install: gem install bundler -v 1.10.6 5 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | require 'quickstrings' 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in quickstrings.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rspec/core/rake_task" 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task :default => :spec 7 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | bundle install 6 | 7 | # Do any other automated setup that you need to do here 8 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 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 15 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 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. 22 | -------------------------------------------------------------------------------- /quickstrings.gemspec: -------------------------------------------------------------------------------- 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 36 | -------------------------------------------------------------------------------- /spec/quickstrings_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Quickstrings do 4 | it 'has a version number' do 5 | expect(Quickstrings::VERSION).not_to be nil 6 | end 7 | 8 | it 'generates a url' do 9 | expect(Quickstrings.url).to eq('http://www.google.com') 10 | end 11 | 12 | it 'generates a string from an array' do 13 | expect(Quickstrings.whitelist_string(['a'],1)).to eq('a') 14 | end 15 | 16 | it 'generates a string from a single character' do 17 | expect(Quickstrings.whitelist_string("m",3)).to eq('mmm') 18 | end 19 | 20 | it 'generates a string from a fixnum' do 21 | expect(Quickstrings.whitelist_string('123',4)).to match(/[1-3]{4}/) 22 | end 23 | 24 | it 'generates a string from a range' do 25 | expect(Quickstrings.whitelist_string(('a'..'z'),3)).to match(/[a-z]{3}/) 26 | end 27 | 28 | it 'generates a random string with a-z characters' do 29 | expect(Quickstrings.rstring(10)).to match(/[a-z]{10}/) 30 | end 31 | 32 | it 'generates a random string with delimiters' do 33 | expect(Quickstrings.rstring(10,'Q')).to match(/Q[a-z]{8}Q/) 34 | end 35 | 36 | #it 'generates a string containing UTF8 chars' do 37 | # expect(Quickstrings.rutf8string(10)).to match ... 38 | #end 39 | 40 | it 'generates an image path' do 41 | expect(Quickstrings.image).to match("http://www.gravatar.com/avatar/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") 42 | end 43 | 44 | it 'generates an image of specified size' do 45 | expect(Quickstrings.image 250).to match("http://www.gravatar.com/avatar/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?s=250") 46 | end 47 | 48 | it 'generates a persons first name' do 49 | expect(Quickstrings.fname).to match("Frank") 50 | end 51 | 52 | it 'generates a persons full name' do 53 | expect(Quickstrings.flname).to match("Frank Enstein") 54 | end 55 | 56 | it 'generates an email' do 57 | expect(Quickstrings.email).to match("somebody@example.com") 58 | end 59 | 60 | end 61 | -------------------------------------------------------------------------------- /lib/quickstrings.rb: -------------------------------------------------------------------------------- 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 | module_function 23 | 24 | def url 25 | URLS.first 26 | end 27 | 28 | def rurl 29 | URLS.sample 30 | end 31 | 32 | def email 33 | EMAILS.first 34 | end 35 | 36 | def remail 37 | EMAILS.sample 38 | end 39 | 40 | def fname 41 | NAMES.first 42 | end 43 | 44 | def rfname 45 | NAMES.sample 46 | end 47 | 48 | def flname 49 | FULLNAMES.first 50 | end 51 | 52 | def rflname 53 | FULLNAMES.sample 54 | end 55 | 56 | def rutf8string(length = 1) 57 | whitelist_string UTF8SAMPLE, length 58 | end 59 | 60 | def image(size = nil) 61 | IMAGES.first + (size.nil? ? "":"?s=#{size}") 62 | end 63 | 64 | def rimage(size = nil) 65 | IMAGES.sample + (size.nil? ? "":"?s=#{size}") 66 | end 67 | 68 | def rstring(length = 1, delim = nil) 69 | new_string = whitelist_string ('a'..'z'), length 70 | if !delim.nil? 71 | new_string[0] = delim 72 | new_string[-1] = delim 73 | end 74 | new_string 75 | end 76 | 77 | 78 | 79 | def whitelist_string(whitelist, length) 80 | 81 | case(whitelist) 82 | when Range 83 | whitelist = whitelist.to_a 84 | when String 85 | whitelist = whitelist.split("") 86 | when Fixnum 87 | whitelist = whitelist.to_s.split("") 88 | end 89 | 90 | output = "" 91 | 92 | length.times do 93 | output += whitelist.sample 94 | end 95 | 96 | output 97 | 98 | end 99 | 100 | end 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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 | 78 | --------------------------------------------------------------------------------