rubyc 0.1.2 → 0.1.3
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/Gemfile +5 -4
- data/Gemfile.lock +10 -5
- data/README.md +20 -13
- data/lib/rubyc/cli.rb +10 -0
- data/lib/rubyc/core_extensions.rb +7 -0
- data/lib/rubyc/version.rb +1 -1
- data/spec/cli_spec.rb +22 -0
- metadata +47 -17
data/Gemfile
CHANGED
@@ -9,14 +9,15 @@ platforms :mri_18 do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
platforms :mri_19 do
|
12
|
-
|
12
|
+
group :development do
|
13
|
+
gem 'ruby-debug19'
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
group :development do
|
16
18
|
gem 'pry'
|
17
19
|
gem 'guard'
|
18
20
|
gem 'guard-minitest'
|
19
|
-
gem 'rb-fsevent'
|
20
|
-
|
21
|
-
# gem 'ruby_gntp', '0.3.4'
|
21
|
+
gem 'rb-fsevent'
|
22
|
+
gem 'ruby_gntp'
|
22
23
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rubyc (0.1.
|
4
|
+
rubyc (0.1.3)
|
5
5
|
thor (~> 0.15)
|
6
6
|
|
7
7
|
GEM
|
@@ -28,8 +28,10 @@ GEM
|
|
28
28
|
ffi (1.1.5)
|
29
29
|
gherkin (2.11.2)
|
30
30
|
json (>= 1.4.6)
|
31
|
-
guard (1.
|
31
|
+
guard (1.5.4)
|
32
32
|
listen (>= 0.4.2)
|
33
|
+
lumberjack (>= 1.0.2)
|
34
|
+
pry (>= 0.9.10)
|
33
35
|
thor (>= 0.14.6)
|
34
36
|
guard-minitest (0.5.0)
|
35
37
|
guard (>= 0.4)
|
@@ -38,7 +40,8 @@ GEM
|
|
38
40
|
rbx-require-relative (> 0.0.4)
|
39
41
|
linecache19 (0.5.12)
|
40
42
|
ruby_core_source (>= 0.1.4)
|
41
|
-
listen (0.5.
|
43
|
+
listen (0.5.3)
|
44
|
+
lumberjack (1.0.2)
|
42
45
|
method_source (0.8)
|
43
46
|
minitest (3.4.0)
|
44
47
|
pry (0.9.10)
|
@@ -46,7 +49,7 @@ GEM
|
|
46
49
|
method_source (~> 0.8)
|
47
50
|
slop (~> 3.3.1)
|
48
51
|
rake (0.9.2.2)
|
49
|
-
rb-fsevent (0.9.
|
52
|
+
rb-fsevent (0.9.2)
|
50
53
|
rbx-require-relative (0.0.9)
|
51
54
|
rspec (2.11.0)
|
52
55
|
rspec-core (~> 2.11.0)
|
@@ -71,6 +74,7 @@ GEM
|
|
71
74
|
ruby-debug-base19 (>= 0.11.19)
|
72
75
|
ruby_core_source (0.1.5)
|
73
76
|
archive-tar-minitar (>= 0.5.2)
|
77
|
+
ruby_gntp (0.3.4)
|
74
78
|
slop (3.3.3)
|
75
79
|
thor (0.16.0)
|
76
80
|
|
@@ -86,7 +90,8 @@ DEPENDENCIES
|
|
86
90
|
minitest
|
87
91
|
pry
|
88
92
|
rake
|
89
|
-
rb-fsevent
|
93
|
+
rb-fsevent
|
90
94
|
ruby-debug (>= 0.10.3)
|
91
95
|
ruby-debug19
|
96
|
+
ruby_gntp
|
92
97
|
rubyc!
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Rubys supports some Enumerable methods applied to each line to the stdin stream.
|
|
16
16
|
|
17
17
|
Rubyc gives you the __line__ variable and ıts shorter alias __l__ to represent the current line on which Rubyc is iterating.
|
18
18
|
|
19
|
-
The __index__ and __lnum__
|
19
|
+
The __index__ and __lnum__ variables are also available to you. The __index__ variable represents the index of the line starting at 0 whereas __lnum__ is the line number which starts at 1.
|
20
20
|
## Examples
|
21
21
|
### Use Case: Upcasing
|
22
22
|
Upcase what is comming from stdin.
|
@@ -48,7 +48,7 @@ The Rubyc way:
|
|
48
48
|
``` bash
|
49
49
|
$ cat file1.csv | rubyc map -r csv 'csv = CSV.parse_line(l); [csv[1], csv[2]]'
|
50
50
|
```
|
51
|
-
NOTE: -r is an alias for the --require= option indicates the gems needed for the exectution of the script. Note that for multiple require,
|
51
|
+
NOTE: -r is an alias for the --require= option indicates the gems needed for the exectution of the script. Note that for multiple require, gem names must me separated with a colon '__:__'.
|
52
52
|
|
53
53
|
### Use Case: Colorize Stderr
|
54
54
|
The shell way:
|
@@ -77,16 +77,23 @@ phone_numbers: 47
|
|
77
77
|
```
|
78
78
|
|
79
79
|
|
80
|
-
|
80
|
+
You can see all the currently supported methods by calling rubyc's help:
|
81
81
|
```
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
82
|
+
$ rubyc help
|
83
|
+
Tasks:
|
84
|
+
rubyc compact # Remove empty lines
|
85
|
+
rubyc count_by BLOCK # Count the number of lines that have the same property. The property is defined by the return value of the gi...
|
86
|
+
rubyc grep BLOCK # Enumerable#grep
|
87
|
+
rubyc help [TASK] # Describe available tasks or one specific task
|
88
|
+
rubyc map BLOCK # Enumerable#map
|
89
|
+
rubyc merge NB_LINES [SEPARATOR] # Merge NB_LINES consecutive lines using SEPARATOR. If SEPARATOR is not given ',' is used
|
90
|
+
rubyc reject BLOCK # Enumerable#reject
|
91
|
+
rubyc scan MATCHER BLOCK # String#scan
|
92
|
+
rubyc select BLOCK # Enumerable#select
|
93
|
+
rubyc sort_by BLOCK # Enumerable#sort_by
|
94
|
+
rubyc sum BLOCK # Active Support Enumerable#sum
|
95
|
+
rubyc uniq # Enumerable#uniq
|
96
|
+
|
97
|
+
Options:
|
98
|
+
-r, [--require=REQUIRE]
|
92
99
|
```
|
data/lib/rubyc/cli.rb
CHANGED
@@ -92,6 +92,16 @@ module Rubyc
|
|
92
92
|
puts $stdin.to_a.uniq
|
93
93
|
end
|
94
94
|
|
95
|
+
desc "uniq_by BLOCK", "TODO"
|
96
|
+
def uniq_by(code = nil)
|
97
|
+
code ||= "line"
|
98
|
+
proc = eval("Proc.new{|line| l = line; #{code}}")
|
99
|
+
counts = $stdin.uniq_by do |line|
|
100
|
+
proc.call(line.chomp)
|
101
|
+
end
|
102
|
+
puts counts
|
103
|
+
end
|
104
|
+
|
95
105
|
desc "compact", "Remove empty lines"
|
96
106
|
def compact
|
97
107
|
$stdin.each{ |line| puts line if line.chomp! != ""}
|
data/lib/rubyc/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -73,6 +73,28 @@ describe "A rubyc cli" do
|
|
73
73
|
out_str.must_equal "1\n2\n3\n"
|
74
74
|
end
|
75
75
|
|
76
|
+
it "should keep unique records grouped by a certain algorithm" do
|
77
|
+
out_str = local_io("aaaCoco\nbbbMomo\naaaBato\nbbbToto") do
|
78
|
+
@cli.uniq_by('[l[0,3], l[3..-1]]')
|
79
|
+
end
|
80
|
+
out_str.must_equal "Coco\nMomo\n"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should merge lines in group of n output them to stdout" do
|
84
|
+
out_str = local_io("1\n2\n3\n4\n5\n6\n7\n8") do
|
85
|
+
@cli.merge(3, ",")
|
86
|
+
end
|
87
|
+
out_str.must_equal "1,2,3\n4,5,6\n7,8\n"
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
it "should merge lines in group of n output them to stdout" do
|
92
|
+
out_str = local_io("1\n2\n3\n4\n5\n6\n7\n8") do
|
93
|
+
@cli.merge(3, ",")
|
94
|
+
end
|
95
|
+
out_str.must_equal "1,2,3\n4,5,6\n7,8\n"
|
96
|
+
end
|
97
|
+
|
76
98
|
it "should merge lines in group of n output them to stdout" do
|
77
99
|
out_str = local_io("1\n2\n3\n4\n5\n6\n7\n8") do
|
78
100
|
@cli.merge(3, ",")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0.15'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.15'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rake
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: bundler
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '1.0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: minitest
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: aruba
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: colorize
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,7 +101,12 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
description: Adds Ruby's powers to the command line
|
81
111
|
email:
|
82
112
|
- chabotm@gmail.com
|
@@ -123,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
153
|
version: '0'
|
124
154
|
segments:
|
125
155
|
- 0
|
126
|
-
hash:
|
156
|
+
hash: 3393431867051759750
|
127
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
158
|
none: false
|
129
159
|
requirements:
|
@@ -132,10 +162,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
162
|
version: '0'
|
133
163
|
segments:
|
134
164
|
- 0
|
135
|
-
hash:
|
165
|
+
hash: 3393431867051759750
|
136
166
|
requirements: []
|
137
167
|
rubyforge_project: rubyc
|
138
|
-
rubygems_version: 1.8.
|
168
|
+
rubygems_version: 1.8.24
|
139
169
|
signing_key:
|
140
170
|
specification_version: 3
|
141
171
|
summary: Adds Ruby's powers to the command line
|