pru 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +7 -3
- data/VERSION +1 -1
- data/lib/pru/core_ext.rb +21 -0
- data/lib/pru.rb +5 -29
- data/pru.gemspec +3 -2
- data/spec/pru_spec.rb +6 -0
- metadata +12 -3
data/Readme.md
CHANGED
@@ -25,7 +25,7 @@ Reduce works on all lines as Array<br/>
|
|
25
25
|
ls -al | pru /foo/
|
26
26
|
|
27
27
|
# grep --- all lines including current date
|
28
|
-
ls -al |
|
28
|
+
ls -al | grep $(date +"%Y-%m-%d")
|
29
29
|
ls -al | pru 'include?(Time.now.strftime("%Y-%m-%d"))'
|
30
30
|
|
31
31
|
# grep --- all lines including foo but not self
|
@@ -60,8 +60,12 @@ Reduce works on all lines as Array<br/>
|
|
60
60
|
# quotes inside a string
|
61
61
|
something | pru 'include?(%{"string"})'
|
62
62
|
|
63
|
-
|
64
|
-
|
63
|
+
Authors
|
64
|
+
=======
|
65
|
+
### [Contributors](http://github.com/grosser/pru/contributors)
|
66
|
+
- [John Hobbs](http://github.com/jmhobbs)
|
67
|
+
- [Vasiliy Ermolovich](http://github.com/nashby)
|
68
|
+
|
65
69
|
[Michael Grosser](http://grosser.it)<br/>
|
66
70
|
michael@grosser.it<br/>
|
67
71
|
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/pru/core_ext.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# http://madeofcode.com/posts/74-ruby-core-extension-array-sum
|
2
|
+
class Array
|
3
|
+
def sum(method = nil, &block)
|
4
|
+
if block_given?
|
5
|
+
raise ArgumentError, "You cannot pass a block and a method!" if method
|
6
|
+
inject(0) { |sum, i| sum + yield(i) }
|
7
|
+
elsif method
|
8
|
+
inject(0) { |sum, i| sum + i.send(method) }
|
9
|
+
else
|
10
|
+
inject(0) { |sum, i| sum + i }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def mean(method = nil, &block)
|
15
|
+
sum(method, &block) / size.to_f
|
16
|
+
end
|
17
|
+
|
18
|
+
def grouped
|
19
|
+
group_by{|x|x}
|
20
|
+
end
|
21
|
+
end
|
data/lib/pru.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pru/core_ext'
|
2
|
+
|
1
3
|
class Pru
|
2
4
|
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
|
3
5
|
|
@@ -8,8 +10,9 @@ class Pru
|
|
8
10
|
end
|
9
11
|
RUBY
|
10
12
|
|
11
|
-
i =
|
12
|
-
io.
|
13
|
+
i = 0
|
14
|
+
io.each_line do |line|
|
15
|
+
i += 1
|
13
16
|
result = line[0..-2]._pru(i)
|
14
17
|
if result == true
|
15
18
|
yield line
|
@@ -18,7 +21,6 @@ class Pru
|
|
18
21
|
elsif result
|
19
22
|
yield result
|
20
23
|
end
|
21
|
-
i += 1
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -31,29 +33,3 @@ class Pru
|
|
31
33
|
array._pru
|
32
34
|
end
|
33
35
|
end
|
34
|
-
|
35
|
-
# http://madeofcode.com/posts/74-ruby-core-extension-array-sum
|
36
|
-
class Array
|
37
|
-
def sum(method = nil, &block)
|
38
|
-
if block_given?
|
39
|
-
raise ArgumentError, "You cannot pass a block and a method!" if method
|
40
|
-
inject(0) { |sum, i| sum + yield(i) }
|
41
|
-
elsif method
|
42
|
-
inject(0) { |sum, i| sum + i.send(method) }
|
43
|
-
else
|
44
|
-
inject(0) { |sum, i| sum + i }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class Array
|
50
|
-
def mean(method = nil, &block)
|
51
|
-
sum(method, &block) / size.to_f
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class Array
|
56
|
-
def grouped
|
57
|
-
group_by{|x|x}
|
58
|
-
end
|
59
|
-
end
|
data/pru.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pru}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
"VERSION",
|
22
22
|
"bin/pru",
|
23
23
|
"lib/pru.rb",
|
24
|
+
"lib/pru/core_ext.rb",
|
24
25
|
"pru.gemspec",
|
25
26
|
"spec/pru_spec.rb",
|
26
27
|
"spec/spec_helper.rb",
|
@@ -28,7 +29,7 @@ Gem::Specification.new do |s|
|
|
28
29
|
]
|
29
30
|
s.homepage = %q{http://github.com/grosser/pru}
|
30
31
|
s.require_paths = ["lib"]
|
31
|
-
s.rubygems_version = %q{1.
|
32
|
+
s.rubygems_version = %q{1.4.2}
|
32
33
|
s.summary = %q{Pipeable Ruby - forget about grep / sed / awk / wc ... use pure, readable Ruby!}
|
33
34
|
s.test_files = [
|
34
35
|
"spec/pru_spec.rb",
|
data/spec/pru_spec.rb
CHANGED
@@ -33,6 +33,12 @@ describe Pru do
|
|
33
33
|
it "can open preserves whitespaces" do
|
34
34
|
`echo ' ab\tcd ' | ./bin/pru 'self'`.should == " ab\tcd \n"
|
35
35
|
end
|
36
|
+
|
37
|
+
it "works with continuous input" do
|
38
|
+
results = `ruby -e 'STDOUT.sync = true; puts 1; sleep 2; puts 1' | ./bin/pru 'Time.now.to_i'`.split("\n")
|
39
|
+
results.size.should == 2
|
40
|
+
results.uniq.size.should == 2 # called at a different time -> parses as you go
|
41
|
+
end
|
36
42
|
end
|
37
43
|
|
38
44
|
describe 'reduce' do
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Michael Grosser
|
@@ -30,6 +35,7 @@ files:
|
|
30
35
|
- VERSION
|
31
36
|
- bin/pru
|
32
37
|
- lib/pru.rb
|
38
|
+
- lib/pru/core_ext.rb
|
33
39
|
- pru.gemspec
|
34
40
|
- spec/pru_spec.rb
|
35
41
|
- spec/spec_helper.rb
|
@@ -48,7 +54,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
54
|
requirements:
|
49
55
|
- - ">="
|
50
56
|
- !ruby/object:Gem::Version
|
51
|
-
hash:
|
57
|
+
hash: 3
|
52
58
|
segments:
|
53
59
|
- 0
|
54
60
|
version: "0"
|
@@ -57,11 +63,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
63
|
requirements:
|
58
64
|
- - ">="
|
59
65
|
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
60
69
|
version: "0"
|
61
70
|
requirements: []
|
62
71
|
|
63
72
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.
|
73
|
+
rubygems_version: 1.4.2
|
65
74
|
signing_key:
|
66
75
|
specification_version: 3
|
67
76
|
summary: Pipeable Ruby - forget about grep / sed / awk / wc ... use pure, readable Ruby!
|