csvutils 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +3 -3
- data/LICENSE.md +116 -0
- data/Manifest.txt +8 -4
- data/README.md +302 -286
- data/Rakefile +30 -26
- data/bin/csvcut +17 -17
- data/bin/csvhead +17 -17
- data/bin/csvheader +17 -17
- data/bin/csvsplit +17 -17
- data/bin/csvstat +17 -17
- data/{test/data → datasets}/at-austria/AUT.csv +363 -363
- data/{test/data → datasets}/de-deutschland/bundesliga.csv +481 -481
- data/{test/data → datasets}/eng-england/2017-18/E0.csv +381 -381
- data/lib/csvutils.rb +32 -31
- data/lib/csvutils/commands/cut.rb +43 -43
- data/lib/csvutils/commands/head.rb +40 -40
- data/lib/csvutils/commands/header.rb +35 -35
- data/lib/csvutils/commands/split.rb +41 -41
- data/lib/csvutils/commands/stat.rb +41 -41
- data/lib/csvutils/cut.rb +43 -50
- data/lib/csvutils/head.rb +22 -25
- data/lib/csvutils/header.rb +16 -28
- data/lib/csvutils/split.rb +106 -107
- data/lib/csvutils/stat.rb +81 -86
- data/lib/csvutils/test.rb +19 -22
- data/lib/csvutils/utils.rb +29 -13
- data/lib/csvutils/version.rb +24 -24
- data/test/helper.rb +16 -16
- data/test/test_cut.rb +31 -0
- data/test/test_head.rb +30 -0
- data/test/{test_headers.rb → test_header.rb} +50 -50
- data/test/test_misc.rb +44 -44
- data/test/test_split.rb +31 -0
- data/test/test_version.rb +20 -20
- metadata +28 -9
data/lib/csvutils.rb
CHANGED
@@ -1,31 +1,32 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
require 'csvutils/
|
15
|
-
require 'csvutils/
|
16
|
-
require 'csvutils/
|
17
|
-
require 'csvutils/
|
18
|
-
require 'csvutils/
|
19
|
-
require 'csvutils/
|
20
|
-
require 'csvutils/
|
21
|
-
|
22
|
-
|
23
|
-
require 'csvutils/commands/
|
24
|
-
require 'csvutils/commands/
|
25
|
-
require 'csvutils/commands/
|
26
|
-
require 'csvutils/commands/
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
|
8
|
+
require 'csvreader'
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
###
|
13
|
+
# our own code
|
14
|
+
require 'csvutils/version' # let version always go first
|
15
|
+
require 'csvutils/utils'
|
16
|
+
require 'csvutils/split'
|
17
|
+
require 'csvutils/cut'
|
18
|
+
require 'csvutils/test'
|
19
|
+
require 'csvutils/stat'
|
20
|
+
require 'csvutils/header'
|
21
|
+
require 'csvutils/head'
|
22
|
+
|
23
|
+
require 'csvutils/commands/head'
|
24
|
+
require 'csvutils/commands/header'
|
25
|
+
require 'csvutils/commands/stat'
|
26
|
+
require 'csvutils/commands/cut'
|
27
|
+
require 'csvutils/commands/split'
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
# say hello
|
32
|
+
puts CsvUtils.banner if $DEBUG || (defined?($RUBYCOCO_DEBUG) && $RUBYCOCO_DEBUG)
|
@@ -1,43 +1,43 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
class CsvTool
|
5
|
-
|
6
|
-
## command line tools
|
7
|
-
def self.cut( args )
|
8
|
-
|
9
|
-
config = { columns: [] }
|
10
|
-
|
11
|
-
parser = OptionParser.new do |opts|
|
12
|
-
opts.banner = "Usage: csvcut [OPTS] source [dest]"
|
13
|
-
|
14
|
-
opts.on("-c", "--columns=COLUMNS", "Name of header columns" ) do |columns|
|
15
|
-
config[:columns] = columns.split(/[,|;]/) ## allow differnt separators
|
16
|
-
end
|
17
|
-
|
18
|
-
opts.on("-h", "--help", "Prints this help") do
|
19
|
-
puts opts
|
20
|
-
exit
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
parser.parse!( args )
|
25
|
-
|
26
|
-
## pp config
|
27
|
-
## pp args
|
28
|
-
|
29
|
-
source = args[0]
|
30
|
-
dest = args[1] || source ## default to same as source (note: overwrites datafile in place!!!)
|
31
|
-
|
32
|
-
unless args[0]
|
33
|
-
puts "** error: arg missing - source filepath required - #{args.inspect}"
|
34
|
-
exit 1
|
35
|
-
end
|
36
|
-
|
37
|
-
columns = config[:columns]
|
38
|
-
|
39
|
-
CsvUtils.cut( source, *columns, output: dest )
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
end # class CsvTool
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
class CsvTool
|
5
|
+
|
6
|
+
## command line tools
|
7
|
+
def self.cut( args )
|
8
|
+
|
9
|
+
config = { columns: [] }
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: csvcut [OPTS] source [dest]"
|
13
|
+
|
14
|
+
opts.on("-c", "--columns=COLUMNS", "Name of header columns" ) do |columns|
|
15
|
+
config[:columns] = columns.split(/[,|;]/) ## allow differnt separators
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on("-h", "--help", "Prints this help") do
|
19
|
+
puts opts
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
parser.parse!( args )
|
25
|
+
|
26
|
+
## pp config
|
27
|
+
## pp args
|
28
|
+
|
29
|
+
source = args[0]
|
30
|
+
dest = args[1] || source ## default to same as source (note: overwrites datafile in place!!!)
|
31
|
+
|
32
|
+
unless args[0]
|
33
|
+
puts "** error: arg missing - source filepath required - #{args.inspect}"
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
columns = config[:columns]
|
38
|
+
|
39
|
+
CsvUtils.cut( source, *columns, output: dest )
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
end # class CsvTool
|
@@ -1,40 +1,40 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
class CsvTool
|
5
|
-
|
6
|
-
## command line tools
|
7
|
-
def self.head( args )
|
8
|
-
|
9
|
-
config = { n: 4 }
|
10
|
-
|
11
|
-
parser = OptionParser.new do |opts|
|
12
|
-
opts.banner = "Usage: csvhead [OPTS] datafile ..."
|
13
|
-
|
14
|
-
opts.on("-n", "--num=NUM", "Number of rows" ) do |num|
|
15
|
-
config[:n] = num.to_i
|
16
|
-
end
|
17
|
-
|
18
|
-
opts.on("-h", "--help", "Prints this help") do
|
19
|
-
puts opts
|
20
|
-
exit
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
parser.parse!( args )
|
25
|
-
|
26
|
-
## pp config
|
27
|
-
## pp args
|
28
|
-
|
29
|
-
args.each do |arg|
|
30
|
-
path = arg
|
31
|
-
n = config[:n]
|
32
|
-
|
33
|
-
puts "== #{File.basename(path)} (#{File.dirname(path)}) =="
|
34
|
-
puts
|
35
|
-
CsvUtils.head( path, n: n )
|
36
|
-
puts
|
37
|
-
end # each arg
|
38
|
-
end
|
39
|
-
|
40
|
-
end # class CsvTool
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
class CsvTool
|
5
|
+
|
6
|
+
## command line tools
|
7
|
+
def self.head( args )
|
8
|
+
|
9
|
+
config = { n: 4 }
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: csvhead [OPTS] datafile ..."
|
13
|
+
|
14
|
+
opts.on("-n", "--num=NUM", "Number of rows" ) do |num|
|
15
|
+
config[:n] = num.to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on("-h", "--help", "Prints this help") do
|
19
|
+
puts opts
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
parser.parse!( args )
|
25
|
+
|
26
|
+
## pp config
|
27
|
+
## pp args
|
28
|
+
|
29
|
+
args.each do |arg|
|
30
|
+
path = arg
|
31
|
+
n = config[:n]
|
32
|
+
|
33
|
+
puts "== #{File.basename(path)} (#{File.dirname(path)}) =="
|
34
|
+
puts
|
35
|
+
CsvUtils.head( path, n: n )
|
36
|
+
puts
|
37
|
+
end # each arg
|
38
|
+
end
|
39
|
+
|
40
|
+
end # class CsvTool
|
@@ -1,35 +1,35 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
class CsvTool
|
5
|
-
|
6
|
-
## command line tools
|
7
|
-
def self.header( args )
|
8
|
-
|
9
|
-
config = {}
|
10
|
-
|
11
|
-
parser = OptionParser.new do |opts|
|
12
|
-
opts.banner = "Usage: csvheader [OPTS] datafile ..."
|
13
|
-
|
14
|
-
opts.on("-h", "--help", "Prints this help") do
|
15
|
-
puts opts
|
16
|
-
exit
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
parser.parse!( args )
|
21
|
-
|
22
|
-
## pp config
|
23
|
-
## pp args
|
24
|
-
|
25
|
-
args.each do |arg|
|
26
|
-
path = arg
|
27
|
-
|
28
|
-
puts "== #{File.basename(path)} (#{File.dirname(path)}) =="
|
29
|
-
puts
|
30
|
-
CsvUtils.pp_header( CsvUtils.header( path ) )
|
31
|
-
puts
|
32
|
-
end # each arg
|
33
|
-
end
|
34
|
-
|
35
|
-
end # class CsvTool
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
class CsvTool
|
5
|
+
|
6
|
+
## command line tools
|
7
|
+
def self.header( args )
|
8
|
+
|
9
|
+
config = {}
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: csvheader [OPTS] datafile ..."
|
13
|
+
|
14
|
+
opts.on("-h", "--help", "Prints this help") do
|
15
|
+
puts opts
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
parser.parse!( args )
|
21
|
+
|
22
|
+
## pp config
|
23
|
+
## pp args
|
24
|
+
|
25
|
+
args.each do |arg|
|
26
|
+
path = arg
|
27
|
+
|
28
|
+
puts "== #{File.basename(path)} (#{File.dirname(path)}) =="
|
29
|
+
puts
|
30
|
+
CsvUtils.pp_header( CsvUtils.header( path ) )
|
31
|
+
puts
|
32
|
+
end # each arg
|
33
|
+
end
|
34
|
+
|
35
|
+
end # class CsvTool
|
@@ -1,41 +1,41 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
class CsvTool
|
5
|
-
|
6
|
-
## command line tools
|
7
|
-
def self.split( args )
|
8
|
-
|
9
|
-
config = { columns: [] }
|
10
|
-
|
11
|
-
parser = OptionParser.new do |opts|
|
12
|
-
opts.banner = "Usage: csvsplit [OPTS] datafile ..."
|
13
|
-
|
14
|
-
opts.on("-c", "--columns=COLUMNS", "Name of header columns" ) do |columns|
|
15
|
-
config[:columns] = columns.split(/[,|;]/) ## allow differnt separators
|
16
|
-
end
|
17
|
-
|
18
|
-
opts.on("-h", "--help", "Prints this help") do
|
19
|
-
puts opts
|
20
|
-
exit
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
parser.parse!( args )
|
25
|
-
|
26
|
-
## pp config
|
27
|
-
## pp args
|
28
|
-
|
29
|
-
args.each do |arg|
|
30
|
-
path = arg
|
31
|
-
columns = config[:columns]
|
32
|
-
|
33
|
-
puts "== #{File.basename(path)} (#{File.dirname(path)}) =="
|
34
|
-
puts
|
35
|
-
CsvUtils.split( path, *columns )
|
36
|
-
puts
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
end # class CsvTool
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
class CsvTool
|
5
|
+
|
6
|
+
## command line tools
|
7
|
+
def self.split( args )
|
8
|
+
|
9
|
+
config = { columns: [] }
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: csvsplit [OPTS] datafile ..."
|
13
|
+
|
14
|
+
opts.on("-c", "--columns=COLUMNS", "Name of header columns" ) do |columns|
|
15
|
+
config[:columns] = columns.split(/[,|;]/) ## allow differnt separators
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on("-h", "--help", "Prints this help") do
|
19
|
+
puts opts
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
parser.parse!( args )
|
25
|
+
|
26
|
+
## pp config
|
27
|
+
## pp args
|
28
|
+
|
29
|
+
args.each do |arg|
|
30
|
+
path = arg
|
31
|
+
columns = config[:columns]
|
32
|
+
|
33
|
+
puts "== #{File.basename(path)} (#{File.dirname(path)}) =="
|
34
|
+
puts
|
35
|
+
CsvUtils.split( path, *columns )
|
36
|
+
puts
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end # class CsvTool
|
@@ -1,41 +1,41 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
class CsvTool
|
5
|
-
|
6
|
-
## command line tools
|
7
|
-
def self.stat( args )
|
8
|
-
|
9
|
-
config = { columns: [] }
|
10
|
-
|
11
|
-
parser = OptionParser.new do |opts|
|
12
|
-
opts.banner = "Usage: csvstat [OPTS] datafile ..."
|
13
|
-
|
14
|
-
opts.on("-c", "--columns=COLUMNS", "Name of header columns" ) do |columns|
|
15
|
-
config[:columns] = columns.split(/[,|;]/) ## allow differnt separators
|
16
|
-
end
|
17
|
-
|
18
|
-
opts.on("-h", "--help", "Prints this help") do
|
19
|
-
puts opts
|
20
|
-
exit
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
parser.parse!( args )
|
25
|
-
|
26
|
-
## pp config
|
27
|
-
## pp args
|
28
|
-
|
29
|
-
args.each do |arg|
|
30
|
-
path = arg
|
31
|
-
columns = config[:columns]
|
32
|
-
|
33
|
-
puts "== #{File.basename(path)} (#{File.dirname(path)}) =="
|
34
|
-
puts
|
35
|
-
CsvUtils.stat( path, *columns )
|
36
|
-
puts
|
37
|
-
end # each arg
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
end # class CsvTool
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
class CsvTool
|
5
|
+
|
6
|
+
## command line tools
|
7
|
+
def self.stat( args )
|
8
|
+
|
9
|
+
config = { columns: [] }
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: csvstat [OPTS] datafile ..."
|
13
|
+
|
14
|
+
opts.on("-c", "--columns=COLUMNS", "Name of header columns" ) do |columns|
|
15
|
+
config[:columns] = columns.split(/[,|;]/) ## allow differnt separators
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on("-h", "--help", "Prints this help") do
|
19
|
+
puts opts
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
parser.parse!( args )
|
25
|
+
|
26
|
+
## pp config
|
27
|
+
## pp args
|
28
|
+
|
29
|
+
args.each do |arg|
|
30
|
+
path = arg
|
31
|
+
columns = config[:columns]
|
32
|
+
|
33
|
+
puts "== #{File.basename(path)} (#{File.dirname(path)}) =="
|
34
|
+
puts
|
35
|
+
CsvUtils.stat( path, *columns )
|
36
|
+
puts
|
37
|
+
end # each arg
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end # class CsvTool
|