rubyc 0.1.2 → 0.3.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 129a515517a551a55fb60a6c2af06819da814828e9dd9a4328532e27a90553e3
4
+ data.tar.gz: 6d5dff8eb1ab16c468045138b7b4a011755abc0b62ef4240cf55ebffb27d35c3
5
+ SHA512:
6
+ metadata.gz: ebcf9c8df0fbdcd5e5b59f075f288773da129a0588dd13dadb4d0b82a860aed3c88ed92df33cae58b0ba22303ae8261179f0be04f70072d0d24a9e4ac432710a
7
+ data.tar.gz: 60138e7cacccc60efd625f81b770d30b21932953801ea68f3f1cfb364d8adfc78328f6791c7eded23f1038243755278e7b7736d37f7ab2792d6656b9683f45b5
data/Gemfile CHANGED
@@ -9,14 +9,15 @@ platforms :mri_18 do
9
9
  end
10
10
 
11
11
  platforms :mri_19 do
12
- gem 'ruby-debug19'
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', '~> 0.9.1'
20
- # gem 'growl', '1.0.3'
21
- # gem 'ruby_gntp', '0.3.4'
21
+ gem 'rb-fsevent', :require => false
22
+ gem 'growl'
22
23
  end
data/Gemfile.lock CHANGED
@@ -1,61 +1,104 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubyc (0.1.2)
4
+ rubyc (0.3.0)
5
5
  thor (~> 0.15)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- archive-tar-minitar (0.5.2)
11
- aruba (0.4.11)
12
- childprocess (>= 0.2.3)
13
- cucumber (>= 1.1.1)
14
- ffi (>= 1.0.11)
15
- rspec (>= 2.7.0)
16
- builder (3.1.3)
17
- childprocess (0.3.5)
18
- ffi (~> 1.0, >= 1.0.6)
19
- coderay (1.0.7)
20
- colorize (0.5.8)
21
- columnize (0.3.6)
22
- cucumber (1.2.1)
23
- builder (>= 2.1.2)
24
- diff-lcs (>= 1.1.3)
25
- gherkin (~> 2.11.0)
26
- json (>= 1.4.6)
27
- diff-lcs (1.1.3)
28
- ffi (1.1.5)
29
- gherkin (2.11.2)
30
- json (>= 1.4.6)
31
- guard (1.3.2)
32
- listen (>= 0.4.2)
33
- thor (>= 0.14.6)
34
- guard-minitest (0.5.0)
35
- guard (>= 0.4)
36
- json (1.7.5)
37
- linecache (0.46)
38
- rbx-require-relative (> 0.0.4)
10
+ archive-tar-minitar (0.8)
11
+ minitar (~> 0.8)
12
+ minitar-cli (~> 0.8)
13
+ aruba (0.14.14)
14
+ childprocess (>= 0.6.3, < 4.0.0)
15
+ contracts (~> 0.9)
16
+ cucumber (>= 1.3.19)
17
+ ffi (~> 1.9)
18
+ rspec-expectations (>= 2.99)
19
+ thor (>= 0.19, < 2.0)
20
+ builder (3.2.4)
21
+ childprocess (3.0.0)
22
+ coderay (1.1.3)
23
+ colorize (0.8.1)
24
+ columnize (0.9.0)
25
+ contracts (0.16.1)
26
+ cucumber (8.0.0)
27
+ builder (~> 3.2, >= 3.2.4)
28
+ cucumber-ci-environment (~> 9.0, >= 9.0.4)
29
+ cucumber-core (~> 11.0, >= 11.0.0)
30
+ cucumber-cucumber-expressions (~> 15.1, >= 15.1.1)
31
+ cucumber-gherkin (~> 23.0, >= 23.0.1)
32
+ cucumber-html-formatter (~> 19.1, >= 19.1.0)
33
+ cucumber-messages (~> 18.0, >= 18.0.0)
34
+ diff-lcs (~> 1.5, >= 1.5.0)
35
+ mime-types (~> 3.4, >= 3.4.1)
36
+ multi_test (~> 1.1, >= 1.1.0)
37
+ sys-uname (~> 1.2, >= 1.2.2)
38
+ cucumber-ci-environment (9.0.4)
39
+ cucumber-core (11.0.0)
40
+ cucumber-gherkin (~> 23.0, >= 23.0.1)
41
+ cucumber-messages (~> 18.0, >= 18.0.0)
42
+ cucumber-tag-expressions (~> 4.1, >= 4.1.0)
43
+ cucumber-cucumber-expressions (15.2.0)
44
+ cucumber-gherkin (23.0.1)
45
+ cucumber-messages (~> 18.0, >= 18.0.0)
46
+ cucumber-html-formatter (19.2.0)
47
+ cucumber-messages (~> 18.0, >= 18.0.0)
48
+ cucumber-messages (18.0.0)
49
+ cucumber-tag-expressions (4.1.0)
50
+ diff-lcs (1.5.0)
51
+ ffi (1.15.5)
52
+ formatador (1.1.0)
53
+ growl (1.0.3)
54
+ guard (2.18.0)
55
+ formatador (>= 0.2.4)
56
+ listen (>= 2.7, < 4.0)
57
+ lumberjack (>= 1.0.12, < 2.0)
58
+ nenv (~> 0.1)
59
+ notiffany (~> 0.0)
60
+ pry (>= 0.13.0)
61
+ shellany (~> 0.0)
62
+ thor (>= 0.18.1)
63
+ guard-compat (1.2.1)
64
+ guard-minitest (2.4.6)
65
+ guard-compat (~> 1.2)
66
+ minitest (>= 3.0)
67
+ hashie (5.0.0)
68
+ linecache (1.3.1)
39
69
  linecache19 (0.5.12)
40
70
  ruby_core_source (>= 0.1.4)
41
- listen (0.5.1)
42
- method_source (0.8)
43
- minitest (3.4.0)
44
- pry (0.9.10)
45
- coderay (~> 1.0.5)
46
- method_source (~> 0.8)
47
- slop (~> 3.3.1)
48
- rake (0.9.2.2)
49
- rb-fsevent (0.9.1)
50
- rbx-require-relative (0.0.9)
51
- rspec (2.11.0)
52
- rspec-core (~> 2.11.0)
53
- rspec-expectations (~> 2.11.0)
54
- rspec-mocks (~> 2.11.0)
55
- rspec-core (2.11.1)
56
- rspec-expectations (2.11.3)
57
- diff-lcs (~> 1.1.3)
58
- rspec-mocks (2.11.2)
71
+ listen (3.7.1)
72
+ rb-fsevent (~> 0.10, >= 0.10.3)
73
+ rb-inotify (~> 0.9, >= 0.9.10)
74
+ lumberjack (1.2.8)
75
+ method_source (1.0.0)
76
+ mime-types (3.4.1)
77
+ mime-types-data (~> 3.2015)
78
+ mime-types-data (3.2022.0105)
79
+ minitar (0.8)
80
+ minitar-cli (0.8)
81
+ minitar (~> 0.8.0)
82
+ powerbar (~> 1.0)
83
+ minitest (5.16.1)
84
+ multi_test (1.1.0)
85
+ nenv (0.3.0)
86
+ notiffany (0.1.3)
87
+ nenv (~> 0.1)
88
+ shellany (~> 0.0)
89
+ powerbar (1.0.18)
90
+ hashie (>= 1.1.0)
91
+ pry (0.14.1)
92
+ coderay (~> 1.1)
93
+ method_source (~> 1.0)
94
+ rake (13.0.6)
95
+ rb-fsevent (0.11.1)
96
+ rb-inotify (0.10.1)
97
+ ffi (~> 1.0)
98
+ rspec-expectations (3.11.0)
99
+ diff-lcs (>= 1.2.0, < 2.0)
100
+ rspec-support (~> 3.11.0)
101
+ rspec-support (3.11.0)
59
102
  ruby-debug (0.10.4)
60
103
  columnize (>= 0.1)
61
104
  ruby-debug-base (~> 0.10.4.0)
@@ -71,22 +114,29 @@ GEM
71
114
  ruby-debug-base19 (>= 0.11.19)
72
115
  ruby_core_source (0.1.5)
73
116
  archive-tar-minitar (>= 0.5.2)
74
- slop (3.3.3)
75
- thor (0.16.0)
117
+ shellany (0.0.1)
118
+ sys-uname (1.2.2)
119
+ ffi (~> 1.1)
120
+ thor (0.20.3)
76
121
 
77
122
  PLATFORMS
78
123
  ruby
124
+ x86_64-darwin-19
79
125
 
80
126
  DEPENDENCIES
81
127
  aruba
82
- bundler (~> 1.0)
128
+ bundler (~> 2.0)
83
129
  colorize
130
+ growl
84
131
  guard
85
132
  guard-minitest
86
133
  minitest
87
134
  pry
88
135
  rake
89
- rb-fsevent (~> 0.9.1)
136
+ rb-fsevent
90
137
  ruby-debug (>= 0.10.3)
91
138
  ruby-debug19
92
139
  rubyc!
140
+
141
+ BUNDLED WITH
142
+ 2.3.17
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__ variable 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.
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, gems must me separated with a :.
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
- Here are the currently supported methods:
80
+ You can see all the currently supported methods by calling rubyc's help:
81
81
  ```
82
- compact # Remove empty lines
83
- count_by # Count the number of lines that have the same property. The property is defined by the return value of the given the block.
84
- grep # Enumerable#grep the first argument is the pattern matcher and the second is the block executed on each line.
85
- map # Apply Enumerable#map on each line and outputs the results of the block by calling to_s on the returned object.
86
- merge # Merge consecutive lines
87
- scan # String#scan
88
- select # Enumerable#select
89
- sort_by # Emumerable#sort_by
90
- sum # Rails Enumerable#sum
91
- uniq # uniq
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/Rakefile CHANGED
@@ -6,11 +6,20 @@ require 'rake/testtask'
6
6
  require 'cucumber'
7
7
  require 'cucumber/rake/task'
8
8
 
9
- Rake::TestTask.new do |t|
10
- t.pattern = "spec/*_spec.rb"
11
- t.libs << 'spec'
9
+ require "minitest/test_task"
10
+
11
+ Minitest::TestTask.create # named test, sensible defaults
12
+
13
+ # or more explicitly:
14
+
15
+ Minitest::TestTask.create(:test) do |t|
16
+ t.libs << "spec"
17
+ t.libs << "lib"
18
+ t.warning = false
19
+ t.test_globs = ["test/**/*_spec.rb"]
12
20
  end
13
21
 
22
+
14
23
  Cucumber::Rake::Task.new(:features) do |t|
15
24
  t.fork = false
16
25
  end
data/lib/rubyc/cli.rb CHANGED
@@ -1,32 +1,35 @@
1
- require 'yaml'
2
- require 'thor'
3
- require 'rubyc/core_extensions'
1
+ require "yaml"
2
+ require "thor"
3
+ require "rubyc/core_extensions"
4
4
 
5
5
  module Rubyc
6
6
  class CLI < Thor
7
- class_option :require, :aliases => '-r'
8
-
7
+ class_option :require, :aliases => "-r"
8
+ class_option :sync, :type => :boolean, :default => false, :aliases => "-s", :banner => "Synchronize stdout"
9
+
9
10
  def initialize(*args)
10
11
  super
11
12
  libs = options[:require] ? options[:require].strip.split(":") : []
12
- libs.each {|lib| require lib}
13
- $stdout.sync = true
13
+ libs.each { |lib| require lib }
14
+ $stdout.sync = options[:sync]
14
15
  end
15
-
16
+
16
17
  def help(*args)
17
- super *args
18
+ super(*args)
18
19
  end
19
20
 
20
21
  desc "map BLOCK", "Enumerable#map"
21
- long_desc "THIS IS A LONG DESCRIPTION"
22
+ long_desc "THIS IS A LONG DESCRIPTION"
23
+
22
24
  def map(code)
23
- proc = eval( "Proc.new{|line,index| l = line; lnum = index + 1;#{code}}" )
25
+ proc = eval("Proc.new{|line,index| l = line; lnum = index + 1;#{code}}")
24
26
  $stdin.each_line.each_with_index do |line, index|
25
27
  puts proc.call(line.chomp, index).to_s
26
28
  end
27
29
  end
28
30
 
29
31
  desc "sum BLOCK", "Active Support Enumerable#sum"
32
+
30
33
  def sum(code = nil)
31
34
  code ||= "line"
32
35
  proc = eval("Proc.new{|line| l = line; #{code}}")
@@ -37,22 +40,25 @@ module Rubyc
37
40
  end
38
41
 
39
42
  desc "select BLOCK", "Enumerable#select"
43
+
40
44
  def select(code)
41
- proc = eval( "Proc.new{|line,index| l = line; lnum = index + 1;#{code}}" )
45
+ proc = eval("Proc.new{|line,index| l = line; lnum = index + 1;#{code}}")
42
46
  $stdin.each_line.each_with_index do |line, index|
43
47
  puts line if proc.call(line.chomp, index)
44
48
  end
45
49
  end
46
50
 
47
51
  desc "reject BLOCK", "Enumerable#reject"
52
+
48
53
  def reject(code)
49
- proc = eval( "Proc.new{|line,index| l = line; lnum = index + 1;#{code}}" )
54
+ proc = eval("Proc.new{|line,index| l = line; lnum = index + 1;#{code}}")
50
55
  $stdin.each_line.each_with_index do |line, index|
51
56
  puts line unless proc.call(line.chomp, index)
52
57
  end
53
58
  end
54
-
59
+
55
60
  desc "count_by BLOCK", "Count the number of lines that have the same property. The property is defined by the return value of the given the block"
61
+
56
62
  def count_by(code = nil)
57
63
  code ||= "line"
58
64
  proc = eval("Proc.new{|line| l = line; #{code}}")
@@ -63,6 +69,7 @@ module Rubyc
63
69
  end
64
70
 
65
71
  desc "sort_by BLOCK", "Enumerable#sort_by"
72
+
66
73
  def sort_by(code = nil)
67
74
  code ||= "line"
68
75
  proc = eval("Proc.new{|line| l = line; #{code}}")
@@ -73,6 +80,7 @@ module Rubyc
73
80
  end
74
81
 
75
82
  desc "grep BLOCK", "Enumerable#grep"
83
+
76
84
  def grep(pattern, code = nil)
77
85
  pattern = eval(pattern)
78
86
  proc = code ? eval("Proc.new{|line| l = line; #{code}}") : nil
@@ -80,6 +88,7 @@ module Rubyc
80
88
  end
81
89
 
82
90
  desc "scan MATCHER BLOCK", "String#scan"
91
+
83
92
  def scan(pattern, code = nil)
84
93
  pattern = eval(pattern)
85
94
  proc = code ? eval("Proc.new{|*match| m = match; #{code}}") : nil
@@ -88,18 +97,32 @@ module Rubyc
88
97
  end
89
98
 
90
99
  desc "uniq", "Enumerable#uniq"
100
+
91
101
  def uniq
92
102
  puts $stdin.to_a.uniq
93
103
  end
94
104
 
105
+ desc "uniq_by BLOCK", "TODO"
106
+
107
+ def uniq_by(code = nil)
108
+ code ||= "line"
109
+ proc = eval("Proc.new{|line| l = line; #{code}}")
110
+ counts = $stdin.uniq_by do |line|
111
+ proc.call(line.chomp)
112
+ end
113
+ puts counts
114
+ end
115
+
95
116
  desc "compact", "Remove empty lines"
117
+
96
118
  def compact
97
- $stdin.each{ |line| puts line if line.chomp! != ""}
119
+ $stdin.each { |line| puts line if line.chomp! != "" }
98
120
  end
99
121
 
100
122
  desc "merge NB_LINES [SEPARATOR]", "Merge NB_LINES consecutive lines using SEPARATOR. If SEPARATOR is not given \',\' is used"
123
+
101
124
  def merge(nb_lines, sep = ",")
102
- $stdin.each_slice(nb_lines.to_i){|chunk| puts chunk.map{|elem| elem.strip}.join(sep)}
125
+ $stdin.each_slice(nb_lines.to_i) { |chunk| puts chunk.map { |elem| elem.strip }.join(sep) }
103
126
  end
104
127
  end
105
128
  end
@@ -8,22 +8,11 @@ module Enumerable
8
8
  end
9
9
  end
10
10
 
11
- # This method was borrowed from ActiveSupport code
12
- def group_by
13
- self.inject({}) do |memo, elem|
14
- key = yield elem
15
- memo[key] ||= []
16
- memo[key] << elem
11
+ def uniq_by
12
+ each_with_index.inject({}) do |memo, (obj, index)|
13
+ val, data = yield obj
14
+ memo[val] ||= data
17
15
  memo
18
- end
19
- end
20
-
21
- # File activesupport/lib/active_support/core_ext/enumerable.rb, line 57
22
- def sum(identity = 0, &block)
23
- if block_given?
24
- map(&block).sum(identity)
25
- else
26
- inject { |sum, element| sum + element } || identity
27
- end
16
+ end.values
28
17
  end
29
18
  end
data/lib/rubyc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rubyc
2
- VERSION = "0.1.2"
2
+ VERSION = "0.3.0"
3
3
  end
data/rubyc.gemspec CHANGED
@@ -7,15 +7,15 @@ Gem::Specification.new do |s|
7
7
  s.version = Rubyc::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Martin Chabot"]
10
+ s.licenses = ["MIT"]
10
11
  s.email = ["chabotm@gmail.com"]
11
12
  s.homepage = "https://github.com/martinos/rubyc"
12
13
  s.summary = %q{Adds Ruby's powers to the command line}
13
14
  s.description = %q{Adds Ruby's powers to the command line}
14
- s.rubyforge_project = "rubyc"
15
15
 
16
16
  s.add_dependency "thor", "~> 0.15"
17
17
  s.add_development_dependency 'rake'
18
- s.add_development_dependency "bundler", "~> 1.0"
18
+ s.add_development_dependency "bundler", "~> 2.0"
19
19
  s.add_development_dependency 'minitest'
20
20
  s.add_development_dependency 'aruba'
21
21
  s.add_development_dependency 'colorize'
data/spec/cli_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
- require 'rubyc/cli'
1
+ require "spec_helper"
2
+ require "rubyc/cli"
3
3
 
4
4
  include SpecHelper
5
5
 
@@ -12,72 +12,94 @@ describe "A rubyc cli" do
12
12
  out_str = local_io("first\nsecond") do
13
13
  @cli.map('"LineNum=#{lnum} Index=#{index}: #{l.upcase}"')
14
14
  end
15
- out_str.must_equal "LineNum=1 Index=0: FIRST\nLineNum=2 Index=1: SECOND\n"
15
+ _(out_str).must_equal "LineNum=1 Index=0: FIRST\nLineNum=2 Index=1: SECOND\n"
16
16
  end
17
17
 
18
18
  it "should select line from stdin and send it to stdout" do
19
19
  out_str = local_io("John Doe\nBlack Jack\nDr Dolittle\nCracker Jack") do
20
- @cli.select('l =~ /Jack/ && lnum == 2 && index == 1')
20
+ @cli.select("l =~ /Jack/ && lnum == 2 && index == 1")
21
21
  end
22
- out_str.must_equal "Black Jack\n"
22
+ _(out_str).must_equal "Black Jack\n"
23
23
  end
24
24
 
25
25
  it "should reject line from stdin and send it to stdout" do
26
26
  out_str = local_io("John Doe\nBlack Jack\nDr Dolittle\nCracker Jack") do
27
- @cli.reject('l =~ /Jack/ && lnum == 2 && index == 1')
27
+ @cli.reject("l =~ /Jack/ && lnum == 2 && index == 1")
28
28
  end
29
- out_str.must_equal "John Doe\nDr Dolittle\nCracker Jack\n"
29
+ _(out_str).must_equal "John Doe\nDr Dolittle\nCracker Jack\n"
30
30
  end
31
31
 
32
32
  it "should sum line from stdin and send it to stdout" do
33
33
  out_str = local_io("1\n2\nthird\n4") do
34
- @cli.sum('l.to_i * 2')
34
+ @cli.sum("l.to_i * 2")
35
35
  end
36
- out_str.must_equal "14\n"
36
+ _(out_str).must_equal "14\n"
37
37
  end
38
38
 
39
39
  it "should sort by stdin and send the result to stdout" do
40
40
  out_str = local_io("a\nbbb\ncc\ndddd") do
41
- @cli.sort_by('l.length')
41
+ @cli.sort_by("l.length")
42
42
  end
43
- out_str.must_equal "a\ncc\nbbb\ndddd\n"
43
+ _(out_str).must_equal "a\ncc\nbbb\ndddd\n"
44
44
  end
45
45
 
46
46
  it "should grep stdin and send the result to stdout" do
47
47
  out_str = local_io("bbbb\nbbb\ncc\ndddd") do
48
- @cli.grep('/^b/', 'l.upcase')
48
+ @cli.grep("/^b/", "l.upcase")
49
49
  end
50
- out_str.must_equal "BBBB\nBBB\n"
50
+ _(out_str).must_equal "BBBB\nBBB\n"
51
51
  end
52
52
 
53
53
  it "should count_by an algorithm and output to stdout" do
54
54
  out_str = local_io("bbbb\nbbb\ncc\ndddd") do
55
- @cli.count_by('l =~ /^(..)/;$1')
56
- end
57
- expected = {"bb" => 2, "cc" => 1, "dd" => 1}
55
+ @cli.count_by("l =~ /^(..)/;$1")
56
+ end
57
+ expected = { "bb" => 2, "cc" => 1, "dd" => 1 }
58
58
 
59
- YAML.load(out_str).must_equal expected
59
+ _(YAML.load(out_str)).must_equal expected
60
60
  end
61
61
 
62
62
  it "should remove empty lines from stdin and output to stdout" do
63
- out_str = local_io("bbbb\n\ncc\n") do
63
+ out_str = local_io("bbbb\n\ncc\n") do
64
64
  @cli.compact
65
65
  end
66
- out_str.must_equal "bbbb\ncc\n"
66
+ _(out_str).must_equal "bbbb\ncc\n"
67
67
  end
68
68
 
69
69
  it "should keep unique lines from stdin and output them to stdout" do
70
70
  out_str = local_io("1\n2\n2\n3") do
71
71
  @cli.uniq
72
72
  end
73
- out_str.must_equal "1\n2\n3\n"
73
+ _(out_str).must_equal "1\n2\n3\n"
74
+ end
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
+ # We test this way since uniq_by uses hashes and on Ruby 1.8.7 hashes are not ordered
81
+ out_array = out_str.split("\n").sort
82
+ _(out_array).must_equal ["Coco", "Momo"]
74
83
  end
75
84
 
76
85
  it "should merge lines in group of n output them to stdout" do
77
86
  out_str = local_io("1\n2\n3\n4\n5\n6\n7\n8") do
78
87
  @cli.merge(3, ",")
79
88
  end
80
- out_str.must_equal "1,2,3\n4,5,6\n7,8\n"
89
+ _(out_str).must_equal "1,2,3\n4,5,6\n7,8\n"
81
90
  end
82
- end
83
91
 
92
+ it "should merge lines in group of n output them to stdout" do
93
+ out_str = local_io("1\n2\n3\n4\n5\n6\n7\n8") do
94
+ @cli.merge(3, ",")
95
+ end
96
+ _(out_str).must_equal "1,2,3\n4,5,6\n7,8\n"
97
+ end
98
+
99
+ it "should merge lines in group of n output them to stdout" do
100
+ out_str = local_io("1\n2\n3\n4\n5\n6\n7\n8") do
101
+ @cli.merge(3, ",")
102
+ end
103
+ _(out_str).must_equal "1,2,3\n4,5,6\n7,8\n"
104
+ end
105
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,13 @@
1
- $:.unshift File.expand_path('..', __FILE__)
2
- $:.unshift File.expand_path('../../lib', __FILE__)
3
- ROOT_PATH = File.expand_path('../..', __FILE__)
4
- require 'rubyc'
5
- require 'minitest/spec'
6
- require 'minitest/autorun'
7
- require 'rubyc/colorize_stack'
1
+ $:.unshift File.expand_path("..", __FILE__)
2
+ $:.unshift File.expand_path("../../lib", __FILE__)
3
+ ROOT_PATH = File.expand_path("../..", __FILE__)
4
+ require "rubyc"
5
+ require "minitest/spec"
6
+ require "minitest/autorun"
8
7
 
9
8
  module SpecHelper
10
9
  def local_io(in_str)
11
- old_stdin, old_stdout = $stdin, $stdout
10
+ old_stdin, old_stdout = $stdin, $stdout
12
11
  $stdin = StringIO.new(in_str)
13
12
  $stdout = StringIO.new
14
13
  yield
@@ -17,4 +16,3 @@ module SpecHelper
17
16
  out_str
18
17
  end
19
18
  end
20
- MiniTest::Unit.output.extend MiniTest::ColorizeStack
metadata CHANGED
@@ -1,82 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Martin Chabot
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-20 00:00:00.000000000 Z
11
+ date: 2022-06-29 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: thor
16
- requirement: &70094492014140 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0.15'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70094492014140
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.15'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rake
27
- requirement: &70094492031300 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70094492031300
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: bundler
38
- requirement: &70094492026780 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ~>
45
+ - - "~>"
42
46
  - !ruby/object:Gem::Version
43
- version: '1.0'
47
+ version: '2.0'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *70094492026780
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: minitest
49
- requirement: &70094492040240 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ! '>='
59
+ - - ">="
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *70094492040240
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: aruba
60
- requirement: &70094492048360 !ruby/object:Gem::Requirement
61
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
62
72
  requirements:
63
- - - ! '>='
73
+ - - ">="
64
74
  - !ruby/object:Gem::Version
65
75
  version: '0'
66
76
  type: :development
67
77
  prerelease: false
68
- version_requirements: *70094492048360
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: colorize
71
- requirement: &70094492044480 !ruby/object:Gem::Requirement
72
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
73
86
  requirements:
74
- - - ! '>='
87
+ - - ">="
75
88
  - !ruby/object:Gem::Version
76
89
  version: '0'
77
90
  type: :development
78
91
  prerelease: false
79
- version_requirements: *70094492044480
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
80
97
  description: Adds Ruby's powers to the command line
81
98
  email:
82
99
  - chabotm@gmail.com
@@ -85,7 +102,7 @@ executables:
85
102
  extensions: []
86
103
  extra_rdoc_files: []
87
104
  files:
88
- - .gitignore
105
+ - ".gitignore"
89
106
  - Gemfile
90
107
  - Gemfile.lock
91
108
  - Guardfile
@@ -102,42 +119,33 @@ files:
102
119
  - features/support/env.rb
103
120
  - lib/rubyc.rb
104
121
  - lib/rubyc/cli.rb
105
- - lib/rubyc/colorize_stack.rb
106
122
  - lib/rubyc/core_extensions.rb
107
123
  - lib/rubyc/version.rb
108
124
  - rubyc.gemspec
109
125
  - spec/cli_spec.rb
110
- - spec/colorize_stack_spec.rb
111
126
  - spec/spec_helper.rb
112
127
  homepage: https://github.com/martinos/rubyc
113
- licenses: []
114
- post_install_message:
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
115
132
  rdoc_options: []
116
133
  require_paths:
117
134
  - lib
118
135
  required_ruby_version: !ruby/object:Gem::Requirement
119
- none: false
120
136
  requirements:
121
- - - ! '>='
137
+ - - ">="
122
138
  - !ruby/object:Gem::Version
123
139
  version: '0'
124
- segments:
125
- - 0
126
- hash: -157925569780101153
127
140
  required_rubygems_version: !ruby/object:Gem::Requirement
128
- none: false
129
141
  requirements:
130
- - - ! '>='
142
+ - - ">="
131
143
  - !ruby/object:Gem::Version
132
144
  version: '0'
133
- segments:
134
- - 0
135
- hash: -157925569780101153
136
145
  requirements: []
137
- rubyforge_project: rubyc
138
- rubygems_version: 1.8.10
139
- signing_key:
140
- specification_version: 3
146
+ rubygems_version: 3.1.2
147
+ signing_key:
148
+ specification_version: 4
141
149
  summary: Adds Ruby's powers to the command line
142
150
  test_files:
143
151
  - features/fixtures/file1.csv
@@ -148,5 +156,4 @@ test_files:
148
156
  - features/step_definitions/rubyc_steps.rb
149
157
  - features/support/env.rb
150
158
  - spec/cli_spec.rb
151
- - spec/colorize_stack_spec.rb
152
159
  - spec/spec_helper.rb
@@ -1,37 +0,0 @@
1
- module MiniTest
2
- # http://blog.macromates.com/2007/the-textmate-url-scheme/
3
- module ColorizeStack
4
- def write(str = "")
5
- str.each_line do |line|
6
- super(colorize_line(line))
7
- end
8
- end
9
-
10
- def colorize_line(line)
11
- red = "\e[31m"
12
- clear = "\e[0m"
13
- green = "\e[32m"
14
- blue = "\e[34m"
15
- magenta = "\e[35m"
16
- clear = "\e[0m"
17
- # test_0001_should_map_stdin_to_stdout(A rubyc cli) [./spec/cli_spec.rb:16]:
18
- # /Users/martinchabot/dev/my_gems/rubyc/spec/cli_spec.rb:16:in `test_0001_should_map_stdin_to_stdout'
19
- url_regex = /(.*?)([.\w\/]*.rb):(\d+)(.*)/
20
- if line =~ url_regex
21
- prefix, file_name, line_number, suffix = $1, $2, $3, $4
22
- if File.exist? file_name
23
- full_path = File.expand_path(file_name)
24
- app_trace = full_path.match(Dir.pwd) && full_path !~ /vendor/
25
- new_line = "#{prefix}#{blue}txmt://open?url=file://#{File.dirname(full_path)}/#{clear}#{red if app_trace }#{File.basename(full_path)}#{clear if app_trace}&line=#{line_number}#{suffix}\n"
26
- else
27
- new_line = line
28
- end
29
- else
30
- new_line = line
31
- end
32
- end
33
- end
34
- end
35
-
36
-
37
-
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
- require 'stringio'
3
-
4
-
5
- describe MiniTest::ColorizeStack do
6
- it 'shoud colorize IO' do
7
- str = <<EOF
8
- test_0003_should_return_the_value_from_on_key(AProductionBafFileSpec::AStructureSpec):
9
- RuntimeError: THIS IS A STACKTRACE TEST
10
- ./lib/rubyc/colorize_stack.rb:19:in `extract_data_from_raw'
11
- ./lib/rubyc/colorize_stack.rb:9:in `initialize'
12
- ./lib/rubyc/colorize_stack.rb:44:in `new'
13
- ./lib/rubyc/colorize_stack.rb:44:in `parse'
14
- ./lib/rubyc/core_extensions.rb:18:in `parse'
15
- ./lib/rubyc/core_extensions.rb:17:in `map'
16
- ./lib/rubyc/core_extensions.rb:17:in `parse'
17
- ./lib/rubyc/core_extensions.rb:26:in `parse'
18
- ./lib/rubyc/core_extensions.rb:39:in `scanned_string'
19
- ./lib/rubyc/core_extensions.rb:16:in `parse'
20
- ./lib/rubyc/core_extensions.rb:27:in `read'
21
- ./spec/spec_helper.rb:8
22
- /Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/spec.rb:118:in `instance_eval'
23
- /Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/spec.rb:118:in `setup'
24
- /Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:713:in `run'
25
- /Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:675:in `run_test_suites'
26
- /Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:669:in `each'
27
- /Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:669:in `run_test_suites'
28
- /Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:668:in `each'
29
- /Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:668:in `run_test_suites'
30
- /Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:632:in `run'
31
- /Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:524:in `autorun'
32
- /Users/martinos/.rvm/gems/ruby-1.8.7-p352@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
33
-
34
- 5 tests, 0 assertions, 0 failures, 5 errors, 0 skips
35
- EOF
36
- out = StringIO.new
37
- out.extend MiniTest::ColorizeStack
38
- out.write(str)
39
- str = out.string
40
- red = "\e\\[31m"
41
- clear = "\e\\[0m"
42
- green = "\e\\[32m"
43
- blue = "\e\\[34m"
44
- magenta = "\e\\[35m"
45
- str.must_match %r{txmt://open\?url=file:///(.*)rubyc/lib/rubyc/(.*)colorize_stack.rb(.*)line=19:in `extract_data_from_raw}
46
- end
47
- end