CSV-datagen 0.0.1 → 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.
- data/README.txt +1 -0
- data/bin/gen-csv.rb +16 -1
- data/lib/gen-data.rb +10 -6
- metadata +2 -2
data/README.txt
CHANGED
@@ -15,3 +15,4 @@ integer - int,<name>,<max value> - the generated number will be between 0..max a
|
|
15
15
|
string - string,<name>,<length> - the generated string had the given name and length.
|
16
16
|
float - float,<name>,<max>,<decimal> - the generated number had the given name, will be between 0..max and had decimal digits after comma.
|
17
17
|
datetime - dtime,<name>,<date format>,<time format> . The date format is a string where user can use the following acronyms - DD for days, MM for months, YYYY or YY for years. The delimiter should be the '/' sign. The time format is "12" for twelve time format or "24" for twenty fours time format.
|
18
|
+
tdate - tdate,<name>,<time format>,<date format>
|
data/bin/gen-csv.rb
CHANGED
@@ -6,7 +6,12 @@ require 'faster_csv'
|
|
6
6
|
|
7
7
|
if $0 == __FILE__
|
8
8
|
puts 'Csv data generator version:'+GenCSV::Version
|
9
|
-
|
9
|
+
unless ARGV.size == 1
|
10
|
+
puts 'usage: gen-csv.rb <parameters file name>'
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
begin
|
14
|
+
reader = GenCSV::ParamsReader.new(ARGV[0])
|
10
15
|
datagen = DataGenerator.new
|
11
16
|
csv = FasterCSV.open(reader.out, "w")
|
12
17
|
if reader.headers
|
@@ -31,10 +36,20 @@ if $0 == __FILE__
|
|
31
36
|
if field[:type] == 'float'
|
32
37
|
element = datagen.gen_float(field[:max], field[:decimal]).to_s
|
33
38
|
end
|
39
|
+
if field[:type] == 'dtime'
|
40
|
+
element = datagen.gen_date(field[:dformat]).to_s + ' ' + datagen.gen_time(field[:tformat]).to_s
|
41
|
+
end
|
42
|
+
if field[:type] == 'tdate'
|
43
|
+
element = datagen.gen_time(field[:tformat]).to_s + ' ' + datagen.gen_date(field[:dformat]).to_s
|
44
|
+
end
|
34
45
|
row.push(element)
|
35
46
|
end
|
36
47
|
csv << row
|
37
48
|
end
|
38
49
|
csv.close
|
39
50
|
puts "Data generation complete"
|
51
|
+
rescue Exception => ex
|
52
|
+
puts 'The following error was occured : ' + ex.to_s
|
53
|
+
end
|
54
|
+
|
40
55
|
end
|
data/lib/gen-data.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
#Class that generate all types of data
|
2
2
|
|
3
3
|
class DataGenerator
|
4
|
-
def gen_int(
|
5
|
-
rand(
|
4
|
+
def gen_int( max )
|
5
|
+
i = rand(max)
|
6
|
+
if i == 0
|
7
|
+
i = 1
|
8
|
+
end
|
9
|
+
return i
|
6
10
|
end
|
7
11
|
|
8
12
|
def gen_string( len )
|
@@ -46,7 +50,7 @@ class DataGenerator
|
|
46
50
|
del = ':'
|
47
51
|
end
|
48
52
|
if fa.size == 1
|
49
|
-
|
53
|
+
raise 'date has unrecognized format'
|
50
54
|
return ''
|
51
55
|
end
|
52
56
|
res = ''
|
@@ -62,7 +66,7 @@ class DataGenerator
|
|
62
66
|
when 'yyyy'
|
63
67
|
res += ( gen_int( 150 ) + 1900).to_s
|
64
68
|
else
|
65
|
-
|
69
|
+
raise 'date has unrecognized format'
|
66
70
|
return ''
|
67
71
|
end
|
68
72
|
res += del
|
@@ -73,7 +77,7 @@ class DataGenerator
|
|
73
77
|
def gen_time( format)
|
74
78
|
fa = format.split(':')
|
75
79
|
if fa.size == 1
|
76
|
-
|
80
|
+
raise 'time has unrecognized format'
|
77
81
|
return ''
|
78
82
|
end
|
79
83
|
is24 = true
|
@@ -101,7 +105,7 @@ class DataGenerator
|
|
101
105
|
when 'ms'
|
102
106
|
res += gen_int(1000).to_s
|
103
107
|
else
|
104
|
-
|
108
|
+
raise 'time has unrecognized format'
|
105
109
|
return ''
|
106
110
|
end
|
107
111
|
res += del
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: CSV-datagen
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2007-
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-04-02 00:00:00 +04:00
|
8
8
|
summary: A free tool for generating random data for testing purposes.
|
9
9
|
require_paths:
|
10
10
|
- lib
|