philiprehberger-random_data 0.3.0 → 0.5.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 +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +37 -0
- data/lib/philiprehberger/random_data/version.rb +1 -1
- data/lib/philiprehberger/random_data.rb +47 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 50f3c7612e67e7214cf57ff2af61567a21efad6111cad8d097801e13fa49b46d
|
|
4
|
+
data.tar.gz: 718650040993a0556ce4185768c577fcd74aa221dfcf46e222c9ed8108798347
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db0d5224d4442603652a0ad80bbba172ccc9045d1916a2745d798e1ed24456e36726cd8b1060b864d3afa29bb40d01240ec5281160e5ab466e73f7ed903283c9
|
|
7
|
+
data.tar.gz: e2cf5bc488ef1d5297778d0821a3c755db65924bbacd06a39bb6b62f28a13deb867c10647a120d3973e77df0d05a3360a292612e744f801572f6b1fdd2dbcde9
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-04-27
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `RandomData.array(of:, size:, **opts)` — generate `size` items by repeatedly calling the named generator; forwards keyword options on every call. Raises `Error` for unknown generator names or negative size.
|
|
14
|
+
- `RandomData.seed!(value)` — seeds Ruby's PRNG for deterministic output across subsequent generators (useful for reproducible test runs and golden-file fixtures). `uuid` and `hex` use `SecureRandom` and are not affected.
|
|
15
|
+
|
|
16
|
+
## [0.4.0] - 2026-04-24
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- `RandomData.coordinates` — returns a `{ latitude:, longitude: }` hash with latitude in `-90.0..90.0` and longitude in `-180.0..180.0`
|
|
20
|
+
|
|
10
21
|
## [0.3.0] - 2026-04-16
|
|
11
22
|
|
|
12
23
|
### Added
|
data/README.md
CHANGED
|
@@ -78,6 +78,13 @@ Philiprehberger::RandomData.ipv4 # => "192.45.67.123"
|
|
|
78
78
|
Philiprehberger::RandomData.url # => "https://smith42.com"
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
+
### Coordinates
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
Philiprehberger::RandomData.coordinates
|
|
85
|
+
# => { latitude: 42.7651, longitude: -87.3419 }
|
|
86
|
+
```
|
|
87
|
+
|
|
81
88
|
### Address and Company
|
|
82
89
|
|
|
83
90
|
```ruby
|
|
@@ -96,6 +103,33 @@ Philiprehberger::RandomData.password(length: 8, symbols: false) # => "kQ7mR2nP"
|
|
|
96
103
|
Philiprehberger::RandomData.timestamp # => 2025-08-14 03:22:11 +0000
|
|
97
104
|
```
|
|
98
105
|
|
|
106
|
+
### Bulk Generation
|
|
107
|
+
|
|
108
|
+
`array` calls a generator `size` times and forwards options on every call.
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
Philiprehberger::RandomData.array(of: :email, size: 3)
|
|
112
|
+
# => ["alice.smith@example.com", "bob_jones@test.com", "carol.lee@demo.com"]
|
|
113
|
+
|
|
114
|
+
Philiprehberger::RandomData.array(of: :integer, size: 5, range: 1..10)
|
|
115
|
+
# => [3, 8, 1, 6, 9]
|
|
116
|
+
|
|
117
|
+
Philiprehberger::RandomData.array(of: :address, size: 2)
|
|
118
|
+
# => [{ street: ..., city: ..., state: ..., zip: ... }, ...]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Deterministic Output
|
|
122
|
+
|
|
123
|
+
Seed Ruby's PRNG so subsequent calls produce a deterministic sequence. Useful
|
|
124
|
+
for reproducible test runs and golden-file fixtures. `uuid` and `hex` use
|
|
125
|
+
`SecureRandom` and are not affected.
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
Philiprehberger::RandomData.seed!(42)
|
|
129
|
+
Philiprehberger::RandomData.integer(1..100) # => deterministic value
|
|
130
|
+
Philiprehberger::RandomData.integer(1..100) # => deterministic next value
|
|
131
|
+
```
|
|
132
|
+
|
|
99
133
|
## API
|
|
100
134
|
|
|
101
135
|
| Method | Description |
|
|
@@ -117,12 +151,15 @@ Philiprehberger::RandomData.timestamp # => 2025-08-14 03:22:11 +0000
|
|
|
117
151
|
| `RandomData.sample(array, n)` | Random n elements from array |
|
|
118
152
|
| `RandomData.weighted_pick(array, weights:)` | Random element chosen proportionally to matching weights |
|
|
119
153
|
| `RandomData.ipv4` | Random IPv4 address |
|
|
154
|
+
| `RandomData.coordinates` | Random `{ latitude:, longitude: }` pair |
|
|
120
155
|
| `RandomData.address` | Random address hash with street, city, state, zip |
|
|
121
156
|
| `RandomData.company` | Random company name |
|
|
122
157
|
| `RandomData.url` | Random URL |
|
|
123
158
|
| `RandomData.color` | Random hex color string |
|
|
124
159
|
| `RandomData.password(length:, symbols:)` | Random password |
|
|
125
160
|
| `RandomData.timestamp(range)` | Random Time object |
|
|
161
|
+
| `RandomData.array(of:, size:, **opts)` | Generate `size` items by repeatedly calling the named generator; forwards `opts` |
|
|
162
|
+
| `RandomData.seed!(value)` | Seed Ruby's PRNG so subsequent generators are deterministic; returns the previous seed |
|
|
126
163
|
|
|
127
164
|
## Development
|
|
128
165
|
|
|
@@ -151,6 +151,18 @@ module Philiprehberger
|
|
|
151
151
|
Array.new(4) { rand(1..254) }.join('.')
|
|
152
152
|
end
|
|
153
153
|
|
|
154
|
+
# Generate a random geographic coordinate pair.
|
|
155
|
+
#
|
|
156
|
+
# Latitude is drawn uniformly from `-90.0..90.0` and longitude from
|
|
157
|
+
# `-180.0..180.0`. The distribution is not area-weighted — it samples
|
|
158
|
+
# the latitude axis uniformly, not over a sphere — which is usually
|
|
159
|
+
# what test fixtures want.
|
|
160
|
+
#
|
|
161
|
+
# @return [Hash{Symbol => Float}] `{ latitude:, longitude: }`
|
|
162
|
+
def self.coordinates
|
|
163
|
+
{ latitude: float(-90.0..90.0), longitude: float(-180.0..180.0) }
|
|
164
|
+
end
|
|
165
|
+
|
|
154
166
|
# Generate a random address
|
|
155
167
|
#
|
|
156
168
|
# @return [Hash] address with street, city, state, zip
|
|
@@ -211,5 +223,40 @@ module Philiprehberger
|
|
|
211
223
|
Time.now - rand(0..(365 * 24 * 60 * 60))
|
|
212
224
|
end
|
|
213
225
|
end
|
|
226
|
+
|
|
227
|
+
# Generate an array of `size` items by repeatedly calling the named generator.
|
|
228
|
+
# Extra options are forwarded to the generator on every call.
|
|
229
|
+
#
|
|
230
|
+
# @example
|
|
231
|
+
# RandomData.array(of: :email, size: 3)
|
|
232
|
+
# RandomData.array(of: :integer, size: 5, range: 1..10)
|
|
233
|
+
#
|
|
234
|
+
# @param of [Symbol] generator method name (must be a public method on this module other than `array`)
|
|
235
|
+
# @param size [Integer] number of items to generate (must be >= 0)
|
|
236
|
+
# @param opts [Hash] keyword arguments forwarded to the generator
|
|
237
|
+
# @return [Array] generated items
|
|
238
|
+
# @raise [Error] if `of` is not a known generator or `size` is negative
|
|
239
|
+
def self.array(of:, size:, **opts)
|
|
240
|
+
raise Error, 'size must be a non-negative Integer' unless size.is_a?(Integer) && size >= 0
|
|
241
|
+
raise Error, "unknown generator: #{of}" unless of != :array && respond_to?(of)
|
|
242
|
+
|
|
243
|
+
Array.new(size) do
|
|
244
|
+
opts.empty? ? public_send(of) : public_send(of, **opts)
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# Seed Ruby's PRNG so subsequent generators produce a deterministic sequence.
|
|
249
|
+
# Useful for reproducible test runs and golden-file fixtures. Note that methods
|
|
250
|
+
# using `SecureRandom` (`uuid`, `hex`) are not affected — they read from the
|
|
251
|
+
# OS CSPRNG.
|
|
252
|
+
#
|
|
253
|
+
# @param value [Integer] seed value
|
|
254
|
+
# @return [Integer] the previous seed
|
|
255
|
+
# @raise [Error] if `value` is not an Integer
|
|
256
|
+
def self.seed!(value)
|
|
257
|
+
raise Error, 'seed must be an Integer' unless value.is_a?(Integer)
|
|
258
|
+
|
|
259
|
+
Kernel.srand(value)
|
|
260
|
+
end
|
|
214
261
|
end
|
|
215
262
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-random_data
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Generate random test data including names, emails, phone numbers, UUIDs,
|
|
14
14
|
sentences, paragraphs, dates, numbers, and more. Includes 50 first names, 50 last
|