pru 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pru +27 -27
- data/lib/pru.rb +0 -1
- data/lib/pru/core_ext/array.rb +0 -6
- data/lib/pru/version.rb +1 -1
- metadata +4 -5
- data/lib/pru/core_ext/symbol.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7ab83319d415eed24a2650913be76d27c0652a1
|
4
|
+
data.tar.gz: 69d39153bc5388450fb4125e6d66513740e81273
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f21fbb6b7a9925e65176555fe73b732f9708c32dbc202d83555542b710f14ef92bbc6543edb1f0d0b1f21fc38b4f2dbea05c1189a85353e3a49fc0bd74b70d00
|
7
|
+
data.tar.gz: 8c10b8fdd4a47e024c603729b6d5b6b260f0402c4c71e1e0c7fa2f0182c68ca50f4adfee06f389d4bdcfc4b3da2f9d937897b00bf67831ec83bc0b581c528133
|
data/bin/pru
CHANGED
@@ -1,39 +1,36 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'optparse'
|
3
3
|
|
4
|
-
|
4
|
+
# enable local usage from cloned repo
|
5
|
+
root = File.expand_path("../..", __FILE__)
|
6
|
+
$LOAD_PATH << "#{root}/lib" if File.exist?("#{root}/Gemfile")
|
7
|
+
|
5
8
|
require 'pru'
|
6
9
|
|
7
10
|
usage = nil
|
8
11
|
options = {}
|
9
12
|
|
10
13
|
OptionParser.new do |opts|
|
11
|
-
opts.banner =
|
12
|
-
Pipeable Ruby
|
14
|
+
opts.banner = <<-BANNER.gsub(/^ /, "")
|
15
|
+
Pipeable Ruby
|
13
16
|
|
14
|
-
Use ruby in your pipes, forget about grep / sed / awk / wc ...
|
17
|
+
Use ruby in your pipes, forget about grep / sed / awk / wc ...
|
15
18
|
|
16
|
-
Map works on each line as String
|
17
|
-
Reduce works on all lines as Array (optional or via -r)
|
19
|
+
Map works on each line as String
|
20
|
+
Reduce works on all lines as Array (optional or via -r)
|
18
21
|
|
19
|
-
Usage:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
Usage:
|
23
|
+
something | pru 'map'
|
24
|
+
something | pru 'map' 'reduce'
|
25
|
+
something | pru '' 'reduce'
|
26
|
+
something | pru --reduce 'reduce'
|
24
27
|
|
25
|
-
Options:
|
26
|
-
BANNER
|
28
|
+
Options:
|
29
|
+
BANNER
|
27
30
|
opts.on("-r", "--reduce CODE","reduce via CODE") {|code| options[:reduce] = code }
|
28
31
|
opts.separator ''
|
29
32
|
opts.on('-I', '--libdir DIR', 'Add DIR to load path') { |dir| $LOAD_PATH << dir }
|
30
|
-
opts.on('--require LIB', 'Require LIB (also comma-separated)') { |lib|
|
31
|
-
begin
|
32
|
-
require 'rubygems'
|
33
|
-
rescue LoadError
|
34
|
-
end
|
35
|
-
lib.split(',').each{|l| require l }
|
36
|
-
}
|
33
|
+
opts.on('--require LIB', 'Require LIB (also comma-separated)') { |lib| lib.split(',').each{|l| require l } }
|
37
34
|
opts.on('-i', '--inplace-edit FILE', 'Edit FILE inplace') { |file| options[:file] = file }
|
38
35
|
opts.separator ''
|
39
36
|
opts.on("-h", "--help","Show this.") { puts opts; exit }
|
@@ -41,7 +38,7 @@ BANNER
|
|
41
38
|
usage = opts
|
42
39
|
end.parse!
|
43
40
|
|
44
|
-
if ARGV.empty?
|
41
|
+
if ARGV.empty? && options.empty? # no arguments -> show usage
|
45
42
|
puts usage
|
46
43
|
exit
|
47
44
|
end
|
@@ -50,28 +47,31 @@ abort "Too many arguments, see --help" if ARGV.size > 2
|
|
50
47
|
|
51
48
|
map, reduce = ARGV
|
52
49
|
reduce ||= options[:reduce]
|
53
|
-
map = 'true' if
|
50
|
+
map = 'true' if !map || map.empty?
|
54
51
|
|
55
52
|
if options[:file]
|
56
53
|
output_lines = []
|
57
54
|
input = File.read(options[:file])
|
58
55
|
newline = input[/\r\n|\r|\n/]
|
56
|
+
trailing_newline = (input =~ /#{newline}\Z/)
|
59
57
|
else
|
60
58
|
input = $stdin
|
61
59
|
end
|
62
60
|
|
63
|
-
collector = lambda
|
61
|
+
collector = lambda do |line|
|
64
62
|
output_lines ? output_lines << line : puts(line)
|
65
|
-
|
63
|
+
end
|
66
64
|
|
67
65
|
if reduce
|
68
66
|
results = []
|
69
|
-
Pru.map(input, map){|out| results << out }
|
67
|
+
Pru.map(input, map) { |out| results << out }
|
70
68
|
collector.call Pru.reduce(results, reduce)
|
71
69
|
else
|
72
|
-
Pru.map(input, map){|out| collector.call out }
|
70
|
+
Pru.map(input, map) { |out| collector.call out }
|
73
71
|
end
|
74
72
|
|
75
73
|
if options[:file]
|
76
|
-
|
74
|
+
content = output_lines.join(newline)
|
75
|
+
content << newline if trailing_newline
|
76
|
+
File.write options[:file], content
|
77
77
|
end
|
data/lib/pru.rb
CHANGED
data/lib/pru/core_ext/array.rb
CHANGED
@@ -22,10 +22,4 @@ class Array
|
|
22
22
|
def counted
|
23
23
|
grouped.sort_by{|d, f| -1 * f.size }.map{|d, f| "#{d} : #{f.size}" }
|
24
24
|
end unless method_defined?(:counted)
|
25
|
-
|
26
|
-
def group_by
|
27
|
-
hash = {}
|
28
|
-
each { |x| hash[yield(x)] = x }
|
29
|
-
hash
|
30
|
-
end unless method_defined?(:group_by)
|
31
25
|
end
|
data/lib/pru/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|
@@ -20,7 +20,6 @@ files:
|
|
20
20
|
- bin/pru
|
21
21
|
- lib/pru.rb
|
22
22
|
- lib/pru/core_ext/array.rb
|
23
|
-
- lib/pru/core_ext/symbol.rb
|
24
23
|
- lib/pru/version.rb
|
25
24
|
homepage: https://github.com/grosser/pru
|
26
25
|
licenses:
|
@@ -34,7 +33,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
33
|
requirements:
|
35
34
|
- - ">="
|
36
35
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
36
|
+
version: 2.0.0
|
38
37
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
38
|
requirements:
|
40
39
|
- - ">="
|
@@ -42,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
41
|
version: '0'
|
43
42
|
requirements: []
|
44
43
|
rubyforge_project:
|
45
|
-
rubygems_version: 2.
|
44
|
+
rubygems_version: 2.5.1
|
46
45
|
signing_key:
|
47
46
|
specification_version: 4
|
48
47
|
summary: Pipeable Ruby - forget about grep / sed / awk / wc ... use pure, readable
|