ru 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ad7c3f3ddc9d77fd0352287f8b7ec243c3fac57
4
- data.tar.gz: 200ee9c700cd3326ac54205e893b26e5922d0bb4
3
+ metadata.gz: 6e484ed43d01e2c22efe5fef97a9fcc5850a2570
4
+ data.tar.gz: 9974ca32575573b83ebdecc453dfc6a57b626d3d
5
5
  SHA512:
6
- metadata.gz: 9ab743fde833e704129f635a022baa209437128bf9450eaeec72c693516a4a3d2d394c4afc0e98dc58b827417515b6809051888b3fe0e3277ba2a972d988ee8a
7
- data.tar.gz: 8f1f5625d6f4b1d25907a57a08a55d95c1bf86312f4e3bb3625b27650f6bc154468ab13e14c2a87ebfb7c0a461329cd8c35c45d6bb7f03b87b0245f495e748ea
6
+ metadata.gz: 07aa4a4102fce55f57e8f0da59a9b8f4d5fb97258913b26fd227e3815b2ee43e4407e77012fc94c1fc2b4f67d3325a9a2c27c7eb3d4826faeaf4f202e9dfa10f
7
+ data.tar.gz: 94ea845efdf2ab6b1eab27dfcd62f031bf15d5a87cee35e0fbff92f83f8796589f63f56fd8ad06ba6e043022132f6f893bdaf50b5d53f7a434a9ed63d5e4e860
data/README.md CHANGED
@@ -35,15 +35,17 @@ ru 'map(:to_i).sum' myfile
35
35
  awk '{s+=$1} END {print s}' myfile
36
36
  ```
37
37
 
38
- Any method from Ruby Core and Active Support can be used. Ru also provides new methods to make transformations easier. Here are some variations on the above example:
38
+ Any method from Ruby Core and Active Support can be used. Ru also provides new methods (and modifies [#map](#map)) to make transformations easier. Here are some variations on the above example:
39
39
 
40
40
  ```bash
41
41
  ru 'map(:to_i, 10).sum' myfile
42
42
  ru 'map(:to_i).reduce(&:+)' myfile
43
43
  ru 'each_line.to_i.to_a.sum' myfile
44
44
  ru 'grep(/^\d+$/).map(:to_i).sum' myfile
45
+ ru 'map { |n| n.to_i }.reduce(&:+)' myfile
45
46
  ru 'reduce(0) { |sum, n| sum + n.to_i }' myfile
46
47
  ru 'each_line.match(/(\d+)/)[1].to_i.to_a.sum' myfile
48
+ ru 'map { |n| n.to_i }.reduce(0) { |sum, n| sum + n }' myfile
47
49
  ```
48
50
 
49
51
  See [Examples](#examples) and [Methods](#methods) for more.
@@ -60,7 +62,7 @@ You can now use Ruby in your shell!
60
62
  For example, to sum a list of integers:
61
63
 
62
64
  ```bash
63
- $ echo "2\n3" | ru 'map(:to_i).sum'
65
+ $ printf "2\n3" | ru 'map(:to_i).sum'
64
66
  5
65
67
  ```
66
68
 
@@ -72,7 +74,7 @@ See [Examples](#examples) below, too!
72
74
  Ru reads from stdin:
73
75
 
74
76
  ```bash
75
- $ echo "2\n3" | ru 'map(:to_i).sum'
77
+ $ printf "2\n3" | ru 'map(:to_i).sum'
76
78
  5
77
79
  $ cat myfile | ru 'map(:to_i).sum'
78
80
  5
@@ -96,43 +98,7 @@ $ ru '! 2 + 3'
96
98
 
97
99
  The code argument is run as if it has `$stdin.each_line.map(&:chomp).` prepended to it. The result is converted to a string and printed. So, if you run `ru 'map(&:to_i).sum'`, you can think of it as running `puts $stdin.each_line.map(&:chomp).map(&:to_i).sum`.
98
100
 
99
- In addition to the methods provided by Ruby Core and Active Support, Ru provides other methods for performing transformations, like `each_line`, `files`, and `grep`. See [Methods](#methods) for more.
100
-
101
- ### Saving commands
102
-
103
- You can save commands for future use using `save`:
104
-
105
- ```bash
106
- $ ru save sum 'map(:to_i).sum'
107
- Saved command: sum is 'map(:to_i).sum'
108
- ```
109
-
110
- And run them later using `run`:
111
-
112
- ```bash
113
- $ echo "2\n3" | ru run sum
114
- 5
115
- $ ru run sum myfile
116
- 5
117
- ```
118
-
119
- To see all of your saved commands, use `list`:
120
-
121
- ```bash
122
- $ ru list
123
- Saved commands:
124
- sum map(:to_i).sum
125
- ```
126
-
127
- ### Options
128
-
129
- #### -h, --help
130
-
131
- Print a help page.
132
-
133
- #### -v, --version
134
-
135
- Print the installed version of Ru.
101
+ In addition to the methods provided by Ruby Core and Active Support, Ru provides other methods for performing transformations, like `each_line`, `files`, and `grep`, and it improves `map`. See [Methods](#methods) for more.
136
102
 
137
103
  Examples
138
104
  --------
@@ -232,7 +198,7 @@ ru 'each_line.strip.to_a.map(:center, 80)' myfile
232
198
  Converts the lines to `Ru::File` objects (see Ru::File below).
233
199
 
234
200
  ```bash
235
- $ echo "foo.txt" | ru 'files.map(:updated_at).map(:strftime, ""%Y-%m-%d")'
201
+ $ printf "foo.txt" | ru 'files.map(:updated_at).map(:strftime, ""%Y-%m-%d")'
236
202
  2014-11-08
237
203
  ```
238
204
 
@@ -253,20 +219,20 @@ The default format, `'l'`, is shown above. It prints `[omode, owner, group, size
253
219
  Selects lines which match the given regex.
254
220
 
255
221
  ```bash
256
- $ echo "john\npaul\ngeorge" | ru 'grep(/o[h|r]/)'
222
+ $ printf "john\npaul\ngeorge" | ru 'grep(/o[h|r]/)'
257
223
  john
258
224
  george
259
225
  ```
260
226
 
261
227
  #### map
262
228
 
263
- This is the same as `Array#map`, but it adds a new syntax that allows you to easily pass arguments to a method. For example:
229
+ This is the same as [Array#map](http://www.ruby-doc.org/core-2.0/Array.html#method-i-map), but it adds a new syntax that allows you to easily pass arguments to a method. For example:
264
230
 
265
231
  ```bash
266
- $ echo "john\npaul" | ru 'map(:[], 0)'
232
+ $ printf "john\npaul" | ru 'map(:[], 0)'
267
233
  j
268
234
  p
269
- $ echo "john\npaul" | ru 'map(:center, 8, ".")'
235
+ $ printf "john\npaul" | ru 'map(:center, 8, ".")'
270
236
  ..john..
271
237
  ..paul..
272
238
  ```
@@ -274,8 +240,8 @@ $ echo "john\npaul" | ru 'map(:center, 8, ".")'
274
240
  Note that the examples above can also be performed with `each_line`:
275
241
 
276
242
  ```bash
277
- $ echo "john\npaul" | ru 'each_line[0]'
278
- $ echo "john\npaul" | ru 'each_line.center(8, ".")'
243
+ $ printf "john\npaul" | ru 'each_line[0]'
244
+ $ printf "john\npaul" | ru 'each_line.center(8, ".")'
279
245
  ```
280
246
 
281
247
  Ru::File
@@ -302,6 +268,51 @@ The [`files`](#files) method returns an enumerable of `Ru::File`s, which are sim
302
268
  * `updated_at` (alias for mtime)
303
269
  * `world_readable?`
304
270
 
271
+ Saved Commands
272
+ --------------
273
+
274
+ Ru lets you save commands by name, so that you can easily use them later.
275
+
276
+ #### save
277
+
278
+ Save a command for future use:
279
+
280
+ ```bash
281
+ $ ru save sum 'map(:to_i).sum'
282
+ Saved command: sum is 'map(:to_i).sum'
283
+ ```
284
+
285
+ #### run
286
+
287
+ Run a saved command:
288
+
289
+ ```bash
290
+ $ printf "2\n3" | ru run sum
291
+ 5
292
+ $ ru run sum myfile
293
+ 5
294
+ ```
295
+
296
+ #### list
297
+
298
+ List all of your saved commands:
299
+
300
+ ```bash
301
+ $ ru list
302
+ Saved commands:
303
+ sum map(:to_i).sum
304
+ ```
305
+
306
+ Options
307
+ -------
308
+
309
+ #### -h, --help
310
+
311
+ Print a help page.
312
+
313
+ #### -v, --version
314
+
315
+ Print the installed version of Ru.
305
316
 
306
317
  Testing
307
318
  -------
@@ -10,7 +10,7 @@ To sum the lines of a list of integers:
10
10
  ru 'map(:to_i).sum' myfile
11
11
 
12
12
  Ru reads from stdin:
13
- $ echo "2\n3" | ru 'map(:to_i).sum'
13
+ $ printf "2\n3" | ru 'map(:to_i).sum'
14
14
  5
15
15
  $ cat myfile | ru 'map(:to_i).sum'
16
16
  5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- ru (0.1.2)
4
+ ru (0.1.3)
5
5
  activesupport (>= 3.2.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- ru (0.1.2)
4
+ ru (0.1.3)
5
5
  activesupport (>= 3.2.0)
6
6
 
7
7
  GEM
@@ -48,10 +48,6 @@ module Ru
48
48
  delegate_to_array(:select, *args, &block)
49
49
  end
50
50
 
51
- def to_stdout
52
- self
53
- end
54
-
55
51
  def to_a
56
52
  @data
57
53
  end
@@ -64,6 +60,10 @@ module Ru
64
60
  self.to_a.join("\n")
65
61
  end
66
62
 
63
+ def to_self
64
+ self
65
+ end
66
+
67
67
  def ==(other)
68
68
  self.to_a == other.to_a
69
69
  end
@@ -20,7 +20,7 @@ module Ru
20
20
  Ru::Array.new(@array)
21
21
  end
22
22
 
23
- def to_dotsch_output
23
+ def to_stdout
24
24
  to_a.join("\n")
25
25
  end
26
26
 
@@ -62,7 +62,7 @@ module Ru
62
62
  def prepare_code(code)
63
63
  if code.kind_of?(String)
64
64
  if code.start_with?('[')
65
- code = 'to_stdout' + code
65
+ code = 'to_self' + code
66
66
  elsif code.start_with?('! ')
67
67
  code = code[2..-1]
68
68
  end
@@ -71,8 +71,8 @@ module Ru
71
71
  end
72
72
 
73
73
  def prepare_output(output)
74
- if output.respond_to?(:to_dotsch_output)
75
- output = output.to_dotsch_output
74
+ if output.respond_to?(:to_stdout)
75
+ output = output.to_stdout
76
76
  end
77
77
  if output.kind_of?(::Array)
78
78
  output = output.join("\n")
@@ -1,3 +1,3 @@
1
1
  module Ru
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -8,16 +8,16 @@ describe Ru::Iterator do
8
8
  end
9
9
  end
10
10
 
11
- describe "#to_dotsch_output" do
11
+ describe "#to_stdout" do
12
12
  it "returns the string" do
13
13
  iterator = described_class.new(%w{john paul george ringo})
14
- expect(iterator.to_dotsch_output).to eq("john\npaul\ngeorge\nringo")
14
+ expect(iterator.to_stdout).to eq("john\npaul\ngeorge\nringo")
15
15
  end
16
16
 
17
17
  context "with a method called on it" do
18
18
  it "returns the string" do
19
19
  iterator = described_class.new(%w{john paul george ringo})
20
- expect(iterator.to_s.to_dotsch_output).to eq("john\npaul\ngeorge\nringo")
20
+ expect(iterator.to_s.to_stdout).to eq("john\npaul\ngeorge\nringo")
21
21
  end
22
22
  end
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Benner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.2.2
117
+ rubygems_version: 2.4.4
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Ruby in your shell!