dummy_log_generator 0.0.3 → 0.0.4
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 +6 -0
- data/README.md +12 -0
- data/lib/dummy_log_generator/generator.rb +31 -28
- data/lib/dummy_log_generator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38e90f1ce32f540d7c61384166fdfd4ff9f96848
|
4
|
+
data.tar.gz: c12675bd60344e5f33781f02147462867a30a87e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdc71004c1590c96b72db467ac142da5482711171f0706c5236951489d865a8ce5656a4e3c85b4af819d86149168c705ac830ce95644395992c61ae17ad04e32
|
7
|
+
data.tar.gz: 638c8ac586c1e18e72dee2143053657619092dfb6f679ff995d9f7b776a0357965757d452735c75e3e45194fc46be9f5f425adb9436217e05b67ac5a4d9dcf00
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -88,6 +88,10 @@ You can specify following data types to your `field` parameters:
|
|
88
88
|
|
89
89
|
* :string
|
90
90
|
|
91
|
+
* :format
|
92
|
+
|
93
|
+
You can specify a format of string as `%s`.
|
94
|
+
|
91
95
|
* :any
|
92
96
|
|
93
97
|
You can specify an array of strings, then the generator picks one from them randomly
|
@@ -102,6 +106,10 @@ You can specify following data types to your `field` parameters:
|
|
102
106
|
|
103
107
|
* :integer
|
104
108
|
|
109
|
+
* :format
|
110
|
+
|
111
|
+
You can specify a format of string as `%03d`.
|
112
|
+
|
105
113
|
* :range
|
106
114
|
|
107
115
|
You can specify a range of integers, then the generator picks one in the range (uniform) randomly
|
@@ -116,6 +124,10 @@ You can specify following data types to your `field` parameters:
|
|
116
124
|
|
117
125
|
* :float
|
118
126
|
|
127
|
+
* :format
|
128
|
+
|
129
|
+
You can specify a format of string as `%03.1f`.
|
130
|
+
|
119
131
|
* :range
|
120
132
|
|
121
133
|
You can specify a range of float numbers, then the generator picks one in the range (uniform) randomly
|
@@ -38,38 +38,41 @@ module DummyLogGenerator
|
|
38
38
|
@chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a # no symbols and multi-bytes for now
|
39
39
|
end
|
40
40
|
|
41
|
-
def string(length: 8, any: nil, prev: nil, value: nil)
|
42
|
-
if value
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
def string(format: nil, length: 8, any: nil, prev: nil, value: nil)
|
42
|
+
string = if value
|
43
|
+
value.to_s
|
44
|
+
elsif any
|
45
|
+
self.any(any)
|
46
|
+
else
|
47
|
+
Array.new(length){@chars[rand(@chars.size-1)]}.join
|
48
|
+
end
|
49
|
+
format ? sprintf(format, string) : string
|
49
50
|
end
|
50
51
|
|
51
|
-
def integer(range: nil, countup: false, prev: nil, value: nil)
|
52
|
-
if value
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
52
|
+
def integer(format: nil, range: nil, countup: false, prev: nil, value: nil)
|
53
|
+
integer = if value
|
54
|
+
value.to_i
|
55
|
+
elsif range
|
56
|
+
self.range(range)
|
57
|
+
elsif countup
|
58
|
+
prev ||= -1
|
59
|
+
prev.to_i + 1
|
60
|
+
else
|
61
|
+
rand(0..2,147,483,647)
|
62
|
+
end
|
63
|
+
format ? sprintf(format, integer) : integer
|
62
64
|
end
|
63
65
|
|
64
|
-
def float(range: nil, prev: nil, value: nil)
|
65
|
-
if value
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
def float(format: nil, range: nil, prev: nil, value: nil)
|
67
|
+
float = if value
|
68
|
+
value.to_f
|
69
|
+
elsif range
|
70
|
+
self.range(range)
|
71
|
+
else
|
72
|
+
r = rand(1..358)
|
73
|
+
r * Math.cos(r) # cheat
|
74
|
+
end
|
75
|
+
format ? sprintf(format, float) : float
|
73
76
|
end
|
74
77
|
|
75
78
|
def datetime(format: "%Y-%m-%d %H:%M:%S.%3N", random: false, prev: nil, value: nil)
|