csvutils 0.2.2 → 0.3.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.
@@ -1,31 +1,32 @@
1
- # encoding: utf-8
2
-
3
- require 'pp'
4
- require 'csv'
5
- require 'date'
6
- require 'fileutils'
7
- require 'optparse'
8
-
9
-
10
-
11
- ###
12
- # our own code
13
- require 'csvutils/version' # let version always go first
14
- require 'csvutils/utils'
15
- require 'csvutils/split'
16
- require 'csvutils/cut'
17
- require 'csvutils/test'
18
- require 'csvutils/stat'
19
- require 'csvutils/header'
20
- require 'csvutils/head'
21
-
22
- require 'csvutils/commands/head'
23
- require 'csvutils/commands/header'
24
- require 'csvutils/commands/stat'
25
- require 'csvutils/commands/cut'
26
- require 'csvutils/commands/split'
27
-
28
-
29
-
30
-
31
- puts CsvUtils.banner # say hello
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