pru 0.1.1 → 0.1.2

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/Readme.md CHANGED
@@ -4,6 +4,12 @@ Install
4
4
  =======
5
5
  sudo gem install pru
6
6
 
7
+ Working with rvm / many gemsets -> only install once
8
+
9
+ rvm use 1.9.2
10
+ gem install pru
11
+ echo 'alias pru="rvm 1.9.2 exec pru"' >> ~/.bash_profile
12
+
7
13
  Usage
8
14
  =====
9
15
  pru supports mapping and reducing.<br/><br/>
@@ -46,6 +52,11 @@ Reduce works on all lines as Array<br/>
46
52
  # every second line
47
53
  ls -al | pru 'i % 2 == 0'
48
54
 
55
+ # paste-friendly mime-types
56
+ curl https://github.com/mattetti/mimetype-fu/raw/master/lib/mime_types.yml | grep image | pru 'gsub(/(.*): (.*)/, %{"\\1" => "\\2",})'
57
+
58
+ # quotes inside a string
59
+ something | pru 'include?(%{"string"})'
49
60
 
50
61
  Author
51
62
  ======
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/lib/pru.rb CHANGED
@@ -10,7 +10,7 @@ class Pru
10
10
 
11
11
  i = 1
12
12
  io.readlines.each do |line|
13
- result = line._pru(i)
13
+ result = line[0..-2]._pru(i)
14
14
  if result == true
15
15
  yield line
16
16
  elsif result.is_a?(Regexp)
data/pru.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pru}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
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"]
12
- s.date = %q{2011-04-16}
12
+ s.date = %q{2011-04-18}
13
13
  s.default_executable = %q{pru}
14
14
  s.email = %q{michael@grosser.it}
15
15
  s.executables = ["pru"]
@@ -23,7 +23,8 @@ Gem::Specification.new do |s|
23
23
  "lib/pru.rb",
24
24
  "pru.gemspec",
25
25
  "spec/pru_spec.rb",
26
- "spec/spec_helper.rb"
26
+ "spec/spec_helper.rb",
27
+ "spec/test.txt"
27
28
  ]
28
29
  s.homepage = %q{http://github.com/grosser/pru}
29
30
  s.require_paths = ["lib"]
data/spec/pru_spec.rb CHANGED
@@ -1,47 +1,61 @@
1
1
  require File.expand_path('spec/spec_helper')
2
2
 
3
3
  describe Pru do
4
- before :all do
5
- @default = `ls -l | wc -l`
6
- end
7
-
8
4
  it "has a VERSION" do
9
5
  Pru::VERSION.should =~ /^\d+\.\d+\.\d+$/
10
6
  end
11
7
 
12
- it "selects" do
13
- `ls -l | ./bin/pru 'include?("G")'`.split("\n").size.should == 2
14
- end
8
+ describe 'map' do
9
+ it "selects" do
10
+ `ls -l | ./bin/pru 'include?("G")'`.split("\n").size.should == 2
11
+ end
15
12
 
16
- it "can selects via regex" do
17
- `ls -l | ./bin/pru /G/`.split("\n").size.should == 2
18
- end
13
+ it "can selects via regex" do
14
+ `ls -l | ./bin/pru /G/`.split("\n").size.should == 2
15
+ end
19
16
 
20
- it "can selects via i" do
21
- `ls -l | ./bin/pru 'i'`.split("\n")[0...3].should == ["1","2","3"]
22
- end
17
+ it "can selects via i" do
18
+ `cat spec/test.txt | ./bin/pru 'i'`.split("\n")[0...3].should == ["1","2","3"]
19
+ end
23
20
 
24
- it "maps" do
25
- `echo abc | ./bin/pru 'gsub(/a/,"b")'`.should == "bbc\n"
26
- end
21
+ it "maps" do
22
+ `echo abc | ./bin/pru 'gsub(/a/,"b")'`.should == "bbc\n"
23
+ end
27
24
 
28
- it "selects and reduces" do
29
- `ls -l | ./bin/pru 'include?("G")' 'size'`.should == "2\n"
30
- end
25
+ it "selects and reduces" do
26
+ `cat spec/test.txt | ./bin/pru 'include?("abc")' 'size'`.should == "2\n"
27
+ end
31
28
 
32
- it "selects with empty string and reduces" do
33
- `ls -l | ./bin/pru '' 'size'`.should == @default
34
- end
29
+ it "can open files" do
30
+ `echo spec/test.txt | ./bin/pru 'File.read(self)'`.should == File.read('spec/test.txt')
31
+ end
35
32
 
36
- it "reduces" do
37
- `ls -l | ./bin/pru -r 'size'`.should == @default
33
+ it "can open preserves whitespaces" do
34
+ `echo ' ab\tcd ' | ./bin/pru 'self'`.should == " ab\tcd \n"
35
+ end
38
36
  end
39
37
 
40
- it "can sum" do
41
- `echo 5 | ./bin/pru -r 'sum(&:to_i)'`.should == "5\n"
38
+ describe 'reduce' do
39
+ it "reduces" do
40
+ `cat spec/test.txt | ./bin/pru -r 'size'`.should == "5\n"
41
+ end
42
+
43
+ it "prints arrays as newlines" do
44
+ `cat spec/test.txt | ./bin/pru -r 'self'`.should == File.read('spec/test.txt')
45
+ end
46
+
47
+ it "can sum" do
48
+ `cat spec/test.txt | ./bin/pru -r 'sum(&:to_i)'`.should == "1212\n"
49
+ end
50
+
51
+ it "can mean" do
52
+ `cat spec/test.txt | ./bin/pru -r 'mean(&:to_i)'`.should == "242.4\n"
53
+ end
42
54
  end
43
55
 
44
- it "can mean" do
45
- `echo 5 | ./bin/pru -r 'mean(&:to_i)'`.should == "5.0\n"
56
+ describe 'map and reduce' do
57
+ it "selects with empty string and reduces" do
58
+ `cat spec/test.txt | ./bin/pru '' 'size'`.should == "5\n"
59
+ end
46
60
  end
47
61
  end
data/spec/test.txt ADDED
@@ -0,0 +1,5 @@
1
+ abc
2
+ def
3
+ abcdef
4
+ 12
5
+ 1200
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pru
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Grosser
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-16 00:00:00 +02:00
18
+ date: 2011-04-18 00:00:00 +02:00
19
19
  default_executable: pru
20
20
  dependencies: []
21
21
 
@@ -38,6 +38,7 @@ files:
38
38
  - pru.gemspec
39
39
  - spec/pru_spec.rb
40
40
  - spec/spec_helper.rb
41
+ - spec/test.txt
41
42
  has_rdoc: true
42
43
  homepage: http://github.com/grosser/pru
43
44
  licenses: []