philiprehberger-random_data 0.1.0
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 +7 -0
- data/CHANGELOG.md +21 -0
- data/LICENSE +21 -0
- data/README.md +103 -0
- data/lib/philiprehberger/random_data/data.rb +40 -0
- data/lib/philiprehberger/random_data/version.rb +7 -0
- data/lib/philiprehberger/random_data.rb +154 -0
- metadata +55 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a441239782445bb54655de85c9b1b25a999bd599db30de5d65f51fb10c4c86fc
|
|
4
|
+
data.tar.gz: 7f3433b2b1ceb2964fd61d955db4ff8033ac6600b21cdcca5c4cb90c5a35c640
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6aac8842fc9f6de9dd5112cd167099e1b6bac5ee2d183101ba0ca8cbde6501f251bfe22d734bb23edd66dab9e44a14bd9850b69293eb31257249fffb1338b26f
|
|
7
|
+
data.tar.gz: f8e442d3a4078607e5e9fe88be0c08c6b60ecf770c3302566977aad033970607d1531c98b9624aecacaaf43b308cd00bd01fc196c6470031710c3bf698d5a3c7
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this gem will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-03-22
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Initial release
|
|
14
|
+
- Random name generation with 50 first names and 50 last names
|
|
15
|
+
- Random email and phone number generation
|
|
16
|
+
- UUID v4 generation
|
|
17
|
+
- Lorem ipsum sentence and paragraph generation
|
|
18
|
+
- Random integer, float, date, and boolean generation
|
|
19
|
+
- Hex string generation
|
|
20
|
+
- Array pick and sample methods
|
|
21
|
+
- Random IPv4 address generation
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 philiprehberger
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# philiprehberger-random_data
|
|
2
|
+
|
|
3
|
+
[](https://github.com/philiprehberger/rb-random-data/actions/workflows/ci.yml)
|
|
4
|
+
[](https://rubygems.org/gems/philiprehberger-random_data)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Lightweight random test data generator for names, emails, and common types. Includes 50 first names, 50 last names, and lorem ipsum words for realistic test fixtures.
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Ruby >= 3.1
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Add to your Gemfile:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem 'philiprehberger-random_data'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or install directly:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
gem install philiprehberger-random_data
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
require 'philiprehberger/random_data'
|
|
31
|
+
|
|
32
|
+
Philiprehberger::RandomData.name # => "Jessica Martinez"
|
|
33
|
+
Philiprehberger::RandomData.first_name # => "Robert"
|
|
34
|
+
Philiprehberger::RandomData.last_name # => "Johnson"
|
|
35
|
+
Philiprehberger::RandomData.email # => "mary_smith@example.com"
|
|
36
|
+
Philiprehberger::RandomData.phone # => "(555) 123-4567"
|
|
37
|
+
Philiprehberger::RandomData.uuid # => "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Text
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
Philiprehberger::RandomData.sentence # => "Lorem ipsum dolor sit amet."
|
|
44
|
+
Philiprehberger::RandomData.paragraph # => "Consectetur adipiscing elit..."
|
|
45
|
+
Philiprehberger::RandomData.sentence(words: 5) # => "Lorem ipsum dolor sit amet."
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Numbers and Dates
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
Philiprehberger::RandomData.integer(1..100) # => 42
|
|
52
|
+
Philiprehberger::RandomData.float(0.0..1.0) # => 0.7342
|
|
53
|
+
Philiprehberger::RandomData.date # => #<Date: 2026-01-15>
|
|
54
|
+
Philiprehberger::RandomData.boolean # => true
|
|
55
|
+
Philiprehberger::RandomData.hex(8) # => "a3f7b2c1"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Collections
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
colors = %w[red green blue yellow]
|
|
62
|
+
Philiprehberger::RandomData.pick(colors) # => "green"
|
|
63
|
+
Philiprehberger::RandomData.sample(colors, 2) # => ["blue", "red"]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Network
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
Philiprehberger::RandomData.ipv4 # => "192.45.67.123"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## API
|
|
73
|
+
|
|
74
|
+
| Method | Description |
|
|
75
|
+
|--------|-------------|
|
|
76
|
+
| `RandomData.name` | Random full name |
|
|
77
|
+
| `RandomData.first_name` | Random first name |
|
|
78
|
+
| `RandomData.last_name` | Random last name |
|
|
79
|
+
| `RandomData.email` | Random email address |
|
|
80
|
+
| `RandomData.phone` | Random phone number |
|
|
81
|
+
| `RandomData.uuid` | Random UUID v4 |
|
|
82
|
+
| `RandomData.sentence(words:)` | Random lorem ipsum sentence |
|
|
83
|
+
| `RandomData.paragraph(sentences:)` | Random paragraph |
|
|
84
|
+
| `RandomData.integer(range)` | Random integer in range |
|
|
85
|
+
| `RandomData.float(range)` | Random float in range |
|
|
86
|
+
| `RandomData.date(range)` | Random date in range |
|
|
87
|
+
| `RandomData.boolean` | Random true or false |
|
|
88
|
+
| `RandomData.hex(length)` | Random hex string |
|
|
89
|
+
| `RandomData.pick(array)` | Random element from array |
|
|
90
|
+
| `RandomData.sample(array, n)` | Random n elements from array |
|
|
91
|
+
| `RandomData.ipv4` | Random IPv4 address |
|
|
92
|
+
|
|
93
|
+
## Development
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
bundle install
|
|
97
|
+
bundle exec rspec # Run tests
|
|
98
|
+
bundle exec rubocop # Check code style
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Philiprehberger
|
|
4
|
+
module RandomData
|
|
5
|
+
FIRST_NAMES = %w[
|
|
6
|
+
James Mary Robert Patricia John Jennifer Michael Linda David Elizabeth
|
|
7
|
+
William Barbara Richard Susan Joseph Jessica Thomas Sarah Charles Karen
|
|
8
|
+
Christopher Lisa Daniel Nancy Matthew Betty Mark Sandra Donald Ashley
|
|
9
|
+
Steven Emily Paul Kimberly Andrew Donna Joshua Michelle Kenneth Dorothy
|
|
10
|
+
Kevin Carol Brian Amanda George Melissa Edward Deborah Ronald Stephanie
|
|
11
|
+
].freeze
|
|
12
|
+
|
|
13
|
+
LAST_NAMES = %w[
|
|
14
|
+
Smith Johnson Williams Brown Jones Garcia Miller Davis Rodriguez Martinez
|
|
15
|
+
Hernandez Lopez Gonzalez Wilson Anderson Thomas Taylor Moore Jackson Martin
|
|
16
|
+
Lee Perez Thompson White Harris Sanchez Clark Ramirez Lewis Robinson Walker
|
|
17
|
+
Young Allen King Wright Scott Torres Nguyen Hill Flores Green Adams Nelson
|
|
18
|
+
Baker Hall Rivera Campbell Mitchell Carter Roberts Gomez Phillips Evans
|
|
19
|
+
].freeze
|
|
20
|
+
|
|
21
|
+
LOREM_WORDS = %w[
|
|
22
|
+
lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod
|
|
23
|
+
tempor incididunt ut labore et dolore magna aliqua enim ad minim veniam
|
|
24
|
+
quis nostrud exercitation ullamco laboris nisi aliquip ex ea commodo
|
|
25
|
+
consequat duis aute irure in reprehenderit voluptate velit esse cillum
|
|
26
|
+
fugiat nulla pariatur excepteur sint occaecat cupidatat non proident sunt
|
|
27
|
+
culpa qui officia deserunt mollit anim id est
|
|
28
|
+
].freeze
|
|
29
|
+
|
|
30
|
+
EMAIL_DOMAINS = %w[
|
|
31
|
+
example.com test.com mail.test sample.org demo.net
|
|
32
|
+
].freeze
|
|
33
|
+
|
|
34
|
+
PHONE_FORMATS = [
|
|
35
|
+
'(###) ###-####',
|
|
36
|
+
'###-###-####',
|
|
37
|
+
'+1 ### ### ####'
|
|
38
|
+
].freeze
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
require 'date'
|
|
5
|
+
require_relative 'random_data/version'
|
|
6
|
+
require_relative 'random_data/data'
|
|
7
|
+
|
|
8
|
+
module Philiprehberger
|
|
9
|
+
module RandomData
|
|
10
|
+
class Error < StandardError; end
|
|
11
|
+
|
|
12
|
+
# Generate a random full name
|
|
13
|
+
#
|
|
14
|
+
# @return [String] first and last name
|
|
15
|
+
def self.name
|
|
16
|
+
"#{first_name} #{last_name}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Generate a random first name
|
|
20
|
+
#
|
|
21
|
+
# @return [String] first name
|
|
22
|
+
def self.first_name
|
|
23
|
+
FIRST_NAMES.sample
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Generate a random last name
|
|
27
|
+
#
|
|
28
|
+
# @return [String] last name
|
|
29
|
+
def self.last_name
|
|
30
|
+
LAST_NAMES.sample
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Generate a random email address
|
|
34
|
+
#
|
|
35
|
+
# @return [String] email address
|
|
36
|
+
def self.email
|
|
37
|
+
fn = first_name.downcase
|
|
38
|
+
ln = last_name.downcase
|
|
39
|
+
domain = EMAIL_DOMAINS.sample
|
|
40
|
+
separator = ['.', '_', ''].sample
|
|
41
|
+
"#{fn}#{separator}#{ln}@#{domain}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Generate a random phone number
|
|
45
|
+
#
|
|
46
|
+
# @return [String] formatted phone number
|
|
47
|
+
def self.phone
|
|
48
|
+
format = PHONE_FORMATS.sample
|
|
49
|
+
format.gsub('#') { rand(10).to_s }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Generate a random UUID v4
|
|
53
|
+
#
|
|
54
|
+
# @return [String] UUID string
|
|
55
|
+
def self.uuid
|
|
56
|
+
SecureRandom.uuid
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Generate a random sentence
|
|
60
|
+
#
|
|
61
|
+
# @param words [Integer] number of words
|
|
62
|
+
# @return [String] sentence with capitalized first word and period
|
|
63
|
+
def self.sentence(words: rand(5..15))
|
|
64
|
+
selected = Array.new(words) { LOREM_WORDS.sample }
|
|
65
|
+
selected[0] = selected[0].capitalize
|
|
66
|
+
"#{selected.join(' ')}."
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Generate a random paragraph
|
|
70
|
+
#
|
|
71
|
+
# @param sentences [Integer] number of sentences
|
|
72
|
+
# @return [String] paragraph of sentences
|
|
73
|
+
def self.paragraph(sentences: rand(3..7))
|
|
74
|
+
Array.new(sentences) { sentence }.join(' ')
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Generate a random integer within a range
|
|
78
|
+
#
|
|
79
|
+
# @param range [Range] range of integers
|
|
80
|
+
# @return [Integer] random integer
|
|
81
|
+
def self.integer(range = 0..100)
|
|
82
|
+
rand(range)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Generate a random float within a range
|
|
86
|
+
#
|
|
87
|
+
# @param range [Range] range of floats
|
|
88
|
+
# @return [Float] random float
|
|
89
|
+
def self.float(range = 0.0..1.0)
|
|
90
|
+
min = range.min.to_f
|
|
91
|
+
max = range.max.to_f
|
|
92
|
+
min + rand * (max - min)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Generate a random date within a range
|
|
96
|
+
#
|
|
97
|
+
# @param range [Range<Date>] range of dates
|
|
98
|
+
# @return [Date] random date
|
|
99
|
+
def self.date(range = nil)
|
|
100
|
+
if range
|
|
101
|
+
start_date = range.min
|
|
102
|
+
end_date = range.max
|
|
103
|
+
days = (end_date - start_date).to_i
|
|
104
|
+
start_date + rand(0..days)
|
|
105
|
+
else
|
|
106
|
+
today = Date.today
|
|
107
|
+
today - rand(0..365)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Generate a random boolean
|
|
112
|
+
#
|
|
113
|
+
# @return [Boolean] true or false
|
|
114
|
+
def self.boolean
|
|
115
|
+
[true, false].sample
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Generate a random hex string
|
|
119
|
+
#
|
|
120
|
+
# @param length [Integer] number of hex characters
|
|
121
|
+
# @return [String] hex string
|
|
122
|
+
def self.hex(length = 16)
|
|
123
|
+
SecureRandom.hex(length / 2 + 1)[0, length]
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Pick a random element from an array
|
|
127
|
+
#
|
|
128
|
+
# @param array [Array] source array
|
|
129
|
+
# @return [Object] random element
|
|
130
|
+
def self.pick(array)
|
|
131
|
+
raise Error, 'Array must not be empty' if array.nil? || array.empty?
|
|
132
|
+
|
|
133
|
+
array.sample
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Sample n random elements from an array
|
|
137
|
+
#
|
|
138
|
+
# @param array [Array] source array
|
|
139
|
+
# @param n [Integer] number of elements
|
|
140
|
+
# @return [Array] random elements
|
|
141
|
+
def self.sample(array, n)
|
|
142
|
+
raise Error, 'Array must not be empty' if array.nil? || array.empty?
|
|
143
|
+
|
|
144
|
+
array.sample(n)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Generate a random IPv4 address
|
|
148
|
+
#
|
|
149
|
+
# @return [String] IPv4 address
|
|
150
|
+
def self.ipv4
|
|
151
|
+
Array.new(4) { rand(1..254) }.join('.')
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: philiprehberger-random_data
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- philiprehberger
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-03-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Generate random test data including names, emails, phone numbers, UUIDs,
|
|
14
|
+
sentences, paragraphs, dates, numbers, and more. Includes 50 first names, 50 last
|
|
15
|
+
names, and lorem ipsum words for realistic test fixtures.
|
|
16
|
+
email:
|
|
17
|
+
- philiprehberger@users.noreply.github.com
|
|
18
|
+
executables: []
|
|
19
|
+
extensions: []
|
|
20
|
+
extra_rdoc_files: []
|
|
21
|
+
files:
|
|
22
|
+
- CHANGELOG.md
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README.md
|
|
25
|
+
- lib/philiprehberger/random_data.rb
|
|
26
|
+
- lib/philiprehberger/random_data/data.rb
|
|
27
|
+
- lib/philiprehberger/random_data/version.rb
|
|
28
|
+
homepage: https://github.com/philiprehberger/rb-random-data
|
|
29
|
+
licenses:
|
|
30
|
+
- MIT
|
|
31
|
+
metadata:
|
|
32
|
+
homepage_uri: https://github.com/philiprehberger/rb-random-data
|
|
33
|
+
source_code_uri: https://github.com/philiprehberger/rb-random-data
|
|
34
|
+
changelog_uri: https://github.com/philiprehberger/rb-random-data/blob/main/CHANGELOG.md
|
|
35
|
+
rubygems_mfa_required: 'true'
|
|
36
|
+
post_install_message:
|
|
37
|
+
rdoc_options: []
|
|
38
|
+
require_paths:
|
|
39
|
+
- lib
|
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: '3.1'
|
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '0'
|
|
50
|
+
requirements: []
|
|
51
|
+
rubygems_version: 3.5.22
|
|
52
|
+
signing_key:
|
|
53
|
+
specification_version: 4
|
|
54
|
+
summary: Lightweight random test data generator for names, emails, and common types
|
|
55
|
+
test_files: []
|