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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87393b7e11cfd15b9095bd7017a3cc9114862326
4
- data.tar.gz: bebf7667d4944db0f8f780108f766a387e963b0e
3
+ metadata.gz: 38e90f1ce32f540d7c61384166fdfd4ff9f96848
4
+ data.tar.gz: c12675bd60344e5f33781f02147462867a30a87e
5
5
  SHA512:
6
- metadata.gz: d90ec26f92a62473ccc1dd36429ef5f725e5f62448bb80fca062ea981a691fc97a4c72eab4f747632108cd3776e591f922d87240713edc1c719b3ff2047df270
7
- data.tar.gz: 76d4e265b8c44a7cea642c5aa0f469be9aa841a1369c6454fb2059491903b1ba75712b5031ced0939834fe9dc7e674f9c4df1d422f72b39cb3e7b0d92ecf4d6c
6
+ metadata.gz: fdc71004c1590c96b72db467ac142da5482711171f0706c5236951489d865a8ce5656a4e3c85b4af819d86149168c705ac830ce95644395992c61ae17ad04e32
7
+ data.tar.gz: 638c8ac586c1e18e72dee2143053657619092dfb6f679ff995d9f7b776a0357965757d452735c75e3e45194fc46be9f5f425adb9436217e05b67ac5a4d9dcf00
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.0.4
2
+
3
+ Enhancement:
4
+
5
+ * Add `format` option to `string`, `integer`, `float` data type
6
+
1
7
  ### 0.0.3
2
8
 
3
9
  Enhancement:
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
- value.to_s
44
- elsif any
45
- self.any(any)
46
- else
47
- Array.new(length){@chars[rand(@chars.size-1)]}.join
48
- end
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
- value.to_i
54
- elsif range
55
- self.range(range)
56
- elsif countup
57
- prev ||= -1
58
- prev + 1
59
- else
60
- rand(0..2,147,483,647)
61
- end
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
- value.to_f
67
- elsif range
68
- self.range(range)
69
- else
70
- r = rand(1..358)
71
- r * Math.cos(r) # cheat
72
- end
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)
@@ -1,3 +1,3 @@
1
1
  module DummyLogGenerator
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dummy_log_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - sonots