masticate 0.1.4 → 0.1.5
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/bin/masticate +18 -14
- data/lib/masticate/max_rows.rb +2 -5
- data/lib/masticate/version.rb +1 -1
- metadata +7 -7
data/bin/masticate
CHANGED
@@ -9,52 +9,56 @@ options = {}
|
|
9
9
|
OptionParser.new do |opts|
|
10
10
|
opts.banner = "Usage: example.rb [options]"
|
11
11
|
|
12
|
-
opts.on("--format FORMAT", "Specify format") do |v|
|
12
|
+
opts.on("--format FORMAT", String, "Specify format") do |v|
|
13
13
|
options[:format] = v
|
14
14
|
end
|
15
15
|
|
16
|
-
opts.on("--delim DELIMITER", "Specify field delimiter (character or TAB; default is ',')") do |v|
|
16
|
+
opts.on("--delim DELIMITER", String, "Specify field delimiter (character or TAB; default is ',')") do |v|
|
17
17
|
options[:col_sep] = v
|
18
18
|
options[:col_sep] = "\t" if options[:col_sep] == "TAB"
|
19
19
|
end
|
20
20
|
|
21
|
-
opts.on("--quote QUOTE-CHAR", "Specify character used for quoting fields (optional; default is no quoting)") do |char|
|
21
|
+
opts.on("--quote QUOTE-CHAR", String, "Specify character used for quoting fields (optional; default is no quoting)") do |char|
|
22
22
|
options[:quote_char] = char
|
23
23
|
end
|
24
24
|
|
25
|
+
opts.on("--stats", "(for *sniff*) collect & display input stats") do
|
26
|
+
options[:stats] = true
|
27
|
+
end
|
28
|
+
|
25
29
|
opts.on("--fields LIST", Array, "Specify fields to select") do |list|
|
26
30
|
options[:fields] = list
|
27
31
|
end
|
28
32
|
|
29
|
-
opts.on("--field FIELD", "Specify field to convert") do |f|
|
33
|
+
opts.on("--field FIELD", String, "Specify field to convert") do |f|
|
30
34
|
options[:field] = f
|
31
35
|
end
|
32
36
|
|
33
|
-
opts.on("--snip DIRECTIVE", "Specify header fields to snip: first N, or by name") do |f|
|
37
|
+
opts.on("--snip DIRECTIVE", String, "Specify header fields to snip: first N, or by name") do |f|
|
34
38
|
options[:snip] = f.to_i
|
35
39
|
end
|
36
40
|
|
37
|
-
opts.on("--from REGEXP", "Regular expression for gsub conversion") do |s|
|
41
|
+
opts.on("--from REGEXP", String, "Regular expression for gsub conversion") do |s|
|
38
42
|
options[:from] = s
|
39
43
|
end
|
40
44
|
|
41
|
-
opts.on("--to STRING", "Result string for gsub conversion") do |s|
|
45
|
+
opts.on("--to STRING", String, "Result string for gsub conversion") do |s|
|
42
46
|
options[:to] = s
|
43
47
|
end
|
44
48
|
|
45
|
-
opts.on("--inlined", "(for *mend* only) Source file has headers inlined on each line") do |
|
46
|
-
options[:inlined] =
|
49
|
+
opts.on("--inlined", "(for *mend* only) Source file has headers inlined on each line") do |b|
|
50
|
+
options[:inlined] = true
|
47
51
|
end
|
48
52
|
|
49
|
-
opts.on("--dejunk", "(for *mend* only) Expunge junk lines from source") do |
|
50
|
-
options[:dejunk] =
|
53
|
+
opts.on("--dejunk", "(for *mend* only) Expunge junk lines from source") do |b|
|
54
|
+
options[:dejunk] = true
|
51
55
|
end
|
52
56
|
|
53
|
-
opts.on("--by FIELD", "(for *maxrows* only) Field to group by") do |f|
|
57
|
+
opts.on("--by FIELD", String, "(for *maxrows* only) Field to group by") do |f|
|
54
58
|
options[:by] = f
|
55
59
|
end
|
56
60
|
|
57
|
-
opts.on("--max FIELD", "(for *maxrows* only) Field to find max value for") do |f|
|
61
|
+
opts.on("--max FIELD", String, "(for *maxrows* only) Field to find max value for") do |f|
|
58
62
|
options[:max] = f
|
59
63
|
end
|
60
64
|
end.parse!
|
@@ -74,7 +78,7 @@ end
|
|
74
78
|
|
75
79
|
case command
|
76
80
|
when 'sniff'
|
77
|
-
results = Masticate.sniff(filename)
|
81
|
+
results = Masticate.sniff(filename, options)
|
78
82
|
col_sep = results[:col_sep]
|
79
83
|
col_sep = "TAB" if col_sep == "\t"
|
80
84
|
quote_char = results[:quote_char] || "NONE"
|
data/lib/masticate/max_rows.rb
CHANGED
@@ -3,10 +3,7 @@ require "csv"
|
|
3
3
|
|
4
4
|
class Masticate::MaxRows < Masticate::Base
|
5
5
|
def maxrows(opts)
|
6
|
-
|
7
|
-
csv_options = {}
|
8
|
-
csv_options[:col_sep] = opts[:col_sep] if opts[:col_sep]
|
9
|
-
csv_options[:quote_char] = opts[:quote_char] || "\0"
|
6
|
+
standard_options(opts)
|
10
7
|
|
11
8
|
groupby = opts[:by] or raise "missing field to group by"
|
12
9
|
maxon = opts[:max] or raise "missing field to max on"
|
@@ -44,7 +41,7 @@ class Masticate::MaxRows < Masticate::Base
|
|
44
41
|
@output.close if opts[:output]
|
45
42
|
|
46
43
|
{
|
47
|
-
:input_count => input_count,
|
44
|
+
:input_count => @input_count,
|
48
45
|
:output_count => @output_count
|
49
46
|
}
|
50
47
|
end
|
data/lib/masticate/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: masticate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-16 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156618420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.9.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156618420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: guard-rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2156617660 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.7.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156617660
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ruby_gntp
|
38
|
-
requirement: &
|
38
|
+
requirement: &2156616980 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 0.3.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2156616980
|
47
47
|
description: Data file crunching
|
48
48
|
email:
|
49
49
|
- jmay@pobox.com
|