sed 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc.example +1 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +17 -0
- data/README.md +47 -0
- data/Rakefile +13 -0
- data/examples/examples.rb +29 -0
- data/examples/file.txt +3 -0
- data/lib/sed.rb +4 -0
- data/lib/sed/commander.rb +43 -0
- data/lib/sed/runner.rb +23 -0
- data/lib/sed/util.rb +25 -0
- data/lib/sed/version.rb +3 -0
- data/sed.gemspec +22 -0
- data/test/commander_test.rb +133 -0
- data/test/fixtures/input01.txt +3 -0
- data/test/fixtures/output01.txt +3 -0
- data/test/fixtures/output01_ere.txt +3 -0
- data/test/runner_test.rb +26 -0
- data/test/test_helper.rb +7 -0
- data/test/util_test.rb +32 -0
- metadata +103 -0
data/.gitignore
ADDED
data/.rvmrc.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.2@rbmu
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Sed ruby wrapper
|
2
|
+
|
3
|
+
Wrapper for the Unix shell command `sed`.
|
4
|
+
|
5
|
+
## Version
|
6
|
+
|
7
|
+
Usable, but beta version. Use under your own risk :)
|
8
|
+
|
9
|
+
## Prerequisites
|
10
|
+
|
11
|
+
Having the `sed` console command installed.
|
12
|
+
|
13
|
+
## Install
|
14
|
+
|
15
|
+
gem install 'sed'
|
16
|
+
|
17
|
+
## How to use it
|
18
|
+
|
19
|
+
Sed::Runner.new(<file_path>, [opts]) do |s|
|
20
|
+
s.replace(<expresion>, <replacement>)
|
21
|
+
s.replace(<expresion>, <replacement>)
|
22
|
+
s.replace(<expresion>, <replacement>)
|
23
|
+
end
|
24
|
+
|
25
|
+
## Options
|
26
|
+
|
27
|
+
The following options are currently supported
|
28
|
+
|
29
|
+
* output: <output_file_path>, default is `nil`, if `nil` the replacement will be _in place_
|
30
|
+
* extended_regex: {true | false}, default is `false`. Activate _extended regular expresssions_
|
31
|
+
|
32
|
+
## Examples
|
33
|
+
|
34
|
+
Sed::Runner.new(
|
35
|
+
'/tmp/input.txt',
|
36
|
+
:output => '/tmp/output.txt',
|
37
|
+
:extended_regex => true
|
38
|
+
) do |s|
|
39
|
+
s.replace("[aeiou]", "x")
|
40
|
+
s.replace("\s", "-")
|
41
|
+
end
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
MIT License. (c) 2011 Fernando Guillen (http://fernandoguillen.info).
|
46
|
+
|
47
|
+
Built as a project for The Ruby Mendicant University, S7-E1.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative '../lib/sed'
|
2
|
+
|
3
|
+
TMP_PATH = Dir.mktmpdir
|
4
|
+
TMP_FILE_PATH = "#{TMP_PATH}/file.txt"
|
5
|
+
EXAMPLE_FILE_PATH = "#{File.dirname(__FILE__)}/file.txt"
|
6
|
+
|
7
|
+
puts "EXAMPLE 1--------------------------------"
|
8
|
+
FileUtils.copy(EXAMPLE_FILE_PATH, TMP_FILE_PATH)
|
9
|
+
|
10
|
+
Sed::Runner.new(TMP_FILE_PATH) do |s|
|
11
|
+
s.replace('a', '-')
|
12
|
+
s.replace('o', 'XXXX')
|
13
|
+
end
|
14
|
+
|
15
|
+
puts File.read(TMP_FILE_PATH)
|
16
|
+
puts
|
17
|
+
|
18
|
+
puts "EXAMPLE 2--------------------------------"
|
19
|
+
FileUtils.copy(EXAMPLE_FILE_PATH, TMP_FILE_PATH)
|
20
|
+
|
21
|
+
Sed::Runner.new(TMP_FILE_PATH, :extended_regex => true) do |s|
|
22
|
+
s.replace('[aeiou]', 'X')
|
23
|
+
end
|
24
|
+
|
25
|
+
puts File.read(TMP_FILE_PATH)
|
26
|
+
puts
|
27
|
+
|
28
|
+
puts "END"
|
29
|
+
FileUtils.rmtree TMP_PATH
|
data/examples/file.txt
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
Lorem ipsum dolor sit -met, consectetur -dipiscing elit. Null-m neque est, orn-re sit -met f-cilisis non, viverr- -t risus. Fusce nibh lectus, -dipiscing ut consequ-t eget, f-ucibus sed er-t. Vestibulum nec qu-m lectus. Vestibulum eleifend d-pibus leo. M-ecen-s in tellus m-ss-. M-uris in leo vel sem suscipit congue. In eu nibh id libero posuere -uctor. Suspendisse m-ttis mi in nibh gr-vid- scelerisque. Null-m in risus lorem. Quisque turpis sem, ph-retr- eget conv-llis nec, volutp-t et est. Duis non urn- tortor, sit -met interdum felis. Eti-m vit-e metus et turpis viverr- euismod eu sed purus. In l-oreet di-m vel neque s-gittis port- m-ttis ipsum volutp-t. Pr-esent m-lesu-d- dui nec neque pl-cer-t id ph-retr- elit sollicitudin. Proin tellus -rcu, tincidunt -t ull-mcorper eu, lobortis -c tortor. Aliqu-m i-culis dolor -c odio fermentum eget lobortis lorem dignissim. Null- f-cilisis port- mi, in consequ-t di-m euismod quis. Pellentesque h-bit-nt morbi tristique senectus et netus et m-lesu-d- f-mes -c turpis egest-s.
|
2
|
+
|
3
|
+
Aliqu-m et enim nec er-t i-culis m-lesu-d- eu - nisl. Proin commodo commodo luctus. Sed in qu-m et s-pien sollicitudin bibendum. N-m eget i-culis elit. Ph-sellus ligul- nunc, tempor id tristique quis, pellentesque quis m-uris. Sed hendrerit i-culis dolor, nec pellentesque lectus volutp-t -t. Nunc vehicul- null- et er-t orn-re quis bl-ndit di-m imperdiet. In i-culis lectus orci. Cl-ss -ptent t-citi sociosqu -d litor- torquent per conubi- nostr-, per inceptos himen-eos. Vestibulum sod-les tincidunt ipsum, nec s-gittis nisl s-gittis non. Proin eget urn- - qu-m dictum orn-re eu vit-e l-cus. Aliqu-m er-t volutp-t. Null- -ccums-n tristique qu-m, et mollis dui gr-vid- ut.
|
data/lib/sed.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Sed
|
2
|
+
module Commander
|
3
|
+
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def replace(input_file_path, expression, replacement, opts = {})
|
7
|
+
command = "sed #{argv(input_file_path, expression, replacement, opts)}"
|
8
|
+
result = Kernel.system command
|
9
|
+
end
|
10
|
+
|
11
|
+
def argv(input_file_path, expression, replacement, opts = {})
|
12
|
+
result = []
|
13
|
+
|
14
|
+
if opts[:output].nil?
|
15
|
+
result << Sed::Commander.inplace_option
|
16
|
+
end
|
17
|
+
|
18
|
+
if opts[:extended_regex]
|
19
|
+
result << Sed::Commander.extended_regex_option
|
20
|
+
end
|
21
|
+
|
22
|
+
result << "'s/#{expression}/#{replacement}/g'"
|
23
|
+
result << "'#{input_file_path}'"
|
24
|
+
|
25
|
+
if opts[:output]
|
26
|
+
result << "> '#{opts[:output]}'"
|
27
|
+
end
|
28
|
+
|
29
|
+
result.join(' ')
|
30
|
+
end
|
31
|
+
|
32
|
+
def inplace_option
|
33
|
+
return "-i ''" if Sed::Util.osx?
|
34
|
+
return "-i" if Sed::Util.gnu?
|
35
|
+
end
|
36
|
+
|
37
|
+
def extended_regex_option
|
38
|
+
return "-E" if Sed::Util.osx?
|
39
|
+
return "-r" if Sed::Util.gnu?
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/sed/runner.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sed
|
2
|
+
class Runner
|
3
|
+
|
4
|
+
attr_reader :input_file_path, :opts
|
5
|
+
|
6
|
+
def initialize(input_file_path, opts = {}, &blk)
|
7
|
+
@input_file_path = input_file_path
|
8
|
+
@opts = opts
|
9
|
+
|
10
|
+
instance_eval(&blk) if block_given?
|
11
|
+
end
|
12
|
+
|
13
|
+
def replace(expression, replacement)
|
14
|
+
Sed::Commander.replace(
|
15
|
+
input_file_path,
|
16
|
+
expression,
|
17
|
+
replacement,
|
18
|
+
opts
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/sed/util.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Sed
|
2
|
+
module Util
|
3
|
+
|
4
|
+
extend self
|
5
|
+
|
6
|
+
# returns :gnu for Linux version
|
7
|
+
# returns :osx for Mac version
|
8
|
+
def system
|
9
|
+
return @system if @system
|
10
|
+
|
11
|
+
command_exit = Kernel.system "sed --version 2> /dev/null"
|
12
|
+
@system = command_exit ? :gnu : :osx
|
13
|
+
|
14
|
+
return @system
|
15
|
+
end
|
16
|
+
|
17
|
+
def osx?
|
18
|
+
Sed::Util.system == :osx
|
19
|
+
end
|
20
|
+
|
21
|
+
def gnu?
|
22
|
+
Sed::Util.system == :gnu
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/sed/version.rb
ADDED
data/sed.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/sed/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "sed"
|
6
|
+
s.version = Sed::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Fernando Guillen (http://fernandoguillen.info)"]
|
9
|
+
s.email = ["fguillen.mail@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/fguillen/SedWrapper"
|
11
|
+
s.summary = "Wrapper for the Unix shell command `sed`"
|
12
|
+
s.description = "Use the `sed` command from Ruby code"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "sed"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
21
|
+
s.require_path = 'lib'
|
22
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class CommanderTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@tmp_path = Dir.mktmpdir
|
7
|
+
Sed::Util.stubs(:system).returns(:osx)
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
FileUtils.rmtree @tmp_path
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_replace_basic
|
15
|
+
input_file_path = "#{@tmp_path}/input01.txt"
|
16
|
+
|
17
|
+
FileUtils.copy(
|
18
|
+
"#{FIXTURES_PATH}/input01.txt",
|
19
|
+
input_file_path
|
20
|
+
)
|
21
|
+
|
22
|
+
Sed::Commander.replace(
|
23
|
+
input_file_path,
|
24
|
+
"a",
|
25
|
+
"-"
|
26
|
+
)
|
27
|
+
|
28
|
+
assert_equal(
|
29
|
+
File.read("#{FIXTURES_PATH}/output01.txt"),
|
30
|
+
File.read(input_file_path)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_replace_with_output
|
35
|
+
input_file_path = "#{FIXTURES_PATH}/input01.txt"
|
36
|
+
output_file_path = "#{@tmp_path}/output01.txt"
|
37
|
+
|
38
|
+
Sed::Commander.replace(
|
39
|
+
input_file_path,
|
40
|
+
"a",
|
41
|
+
"-",
|
42
|
+
:output => output_file_path
|
43
|
+
)
|
44
|
+
|
45
|
+
assert_equal(
|
46
|
+
File.read("#{FIXTURES_PATH}/output01.txt"),
|
47
|
+
File.read(output_file_path)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_replace_with_output_and_ere
|
52
|
+
input_file_path = "#{FIXTURES_PATH}/input01.txt"
|
53
|
+
output_file_path = "#{@tmp_path}/output02_ere.txt"
|
54
|
+
|
55
|
+
Sed::Commander.replace(
|
56
|
+
input_file_path,
|
57
|
+
"[aeiou]",
|
58
|
+
"-",
|
59
|
+
{
|
60
|
+
:output => output_file_path,
|
61
|
+
:extended_regex => true
|
62
|
+
}
|
63
|
+
)
|
64
|
+
|
65
|
+
assert_equal(
|
66
|
+
File.read("#{FIXTURES_PATH}/output01_ere.txt"),
|
67
|
+
File.read(output_file_path)
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_argv_basic
|
72
|
+
argv =
|
73
|
+
Sed::Commander.argv(
|
74
|
+
'input.txt',
|
75
|
+
'expression',
|
76
|
+
'replacement'
|
77
|
+
)
|
78
|
+
|
79
|
+
assert_equal(
|
80
|
+
"-i '' 's/expression/replacement/g' 'input.txt'",
|
81
|
+
argv
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_argv_with_output
|
86
|
+
argv =
|
87
|
+
Sed::Commander.argv(
|
88
|
+
'input.txt',
|
89
|
+
'expression',
|
90
|
+
'replacement',
|
91
|
+
{ :output => 'output.txt' }
|
92
|
+
)
|
93
|
+
|
94
|
+
assert_equal(
|
95
|
+
"'s/expression/replacement/g' 'input.txt' > 'output.txt'",
|
96
|
+
argv
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_argv_with_ere
|
101
|
+
argv =
|
102
|
+
Sed::Commander.argv(
|
103
|
+
'input.txt',
|
104
|
+
'expression',
|
105
|
+
'replacement',
|
106
|
+
{ :extended_regex => true }
|
107
|
+
)
|
108
|
+
|
109
|
+
assert_equal(
|
110
|
+
"-i '' -E 's/expression/replacement/g' 'input.txt'",
|
111
|
+
argv
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_argv_with_and_output
|
116
|
+
argv =
|
117
|
+
Sed::Commander.argv(
|
118
|
+
'input.txt',
|
119
|
+
'expression',
|
120
|
+
'replacement',
|
121
|
+
{
|
122
|
+
:output => 'output.txt',
|
123
|
+
:extended_regex => true
|
124
|
+
}
|
125
|
+
)
|
126
|
+
|
127
|
+
assert_equal(
|
128
|
+
"-E 's/expression/replacement/g' 'input.txt' > 'output.txt'",
|
129
|
+
argv
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,3 @@
|
|
1
|
+
Lorem ipsum dolor sit -met, consectetur -dipiscing elit. Null-m neque est, orn-re sit -met f-cilisis non, viverr- -t risus. Fusce nibh lectus, -dipiscing ut consequ-t eget, f-ucibus sed er-t. Vestibulum nec qu-m lectus. Vestibulum eleifend d-pibus leo. M-ecen-s in tellus m-ss-. M-uris in leo vel sem suscipit congue. In eu nibh id libero posuere -uctor. Suspendisse m-ttis mi in nibh gr-vid- scelerisque. Null-m in risus lorem. Quisque turpis sem, ph-retr- eget conv-llis nec, volutp-t et est. Duis non urn- tortor, sit -met interdum felis. Eti-m vit-e metus et turpis viverr- euismod eu sed purus. In l-oreet di-m vel neque s-gittis port- m-ttis ipsum volutp-t. Pr-esent m-lesu-d- dui nec neque pl-cer-t id ph-retr- elit sollicitudin. Proin tellus -rcu, tincidunt -t ull-mcorper eu, lobortis -c tortor. Aliqu-m i-culis dolor -c odio fermentum eget lobortis lorem dignissim. Null- f-cilisis port- mi, in consequ-t di-m euismod quis. Pellentesque h-bit-nt morbi tristique senectus et netus et m-lesu-d- f-mes -c turpis egest-s.
|
2
|
+
|
3
|
+
Aliqu-m et enim nec er-t i-culis m-lesu-d- eu - nisl. Proin commodo commodo luctus. Sed in qu-m et s-pien sollicitudin bibendum. N-m eget i-culis elit. Ph-sellus ligul- nunc, tempor id tristique quis, pellentesque quis m-uris. Sed hendrerit i-culis dolor, nec pellentesque lectus volutp-t -t. Nunc vehicul- null- et er-t orn-re quis bl-ndit di-m imperdiet. In i-culis lectus orci. Cl-ss -ptent t-citi sociosqu -d litor- torquent per conubi- nostr-, per inceptos himen-eos. Vestibulum sod-les tincidunt ipsum, nec s-gittis nisl s-gittis non. Proin eget urn- - qu-m dictum orn-re eu vit-e l-cus. Aliqu-m er-t volutp-t. Null- -ccums-n tristique qu-m, et mollis dui gr-vid- ut.
|
@@ -0,0 +1,3 @@
|
|
1
|
+
Lorem ipsum dolor sit -met, consectetur -dipiscing elit. Null-m neque est, orn-re sit -met f-cilisis non, viverr- -t risus. Fusce nibh lectus, -dipiscing ut consequ-t eget, f-ucibus sed er-t. Vestibulum nec qu-m lectus. Vestibulum eleifend d-pibus leo. M-ecen-s in tellus m-ss-. M-uris in leo vel sem suscipit congue. In eu nibh id libero posuere -uctor. Suspendisse m-ttis mi in nibh gr-vid- scelerisque. Null-m in risus lorem. Quisque turpis sem, ph-retr- eget conv-llis nec, volutp-t et est. Duis non urn- tortor, sit -met interdum felis. Eti-m vit-e metus et turpis viverr- euismod eu sed purus. In l-oreet di-m vel neque s-gittis port- m-ttis ipsum volutp-t. Pr-esent m-lesu-d- dui nec neque pl-cer-t id ph-retr- elit sollicitudin. Proin tellus -rcu, tincidunt -t ull-mcorper eu, lobortis -c tortor. Aliqu-m i-culis dolor -c odio fermentum eget lobortis lorem dignissim. Null- f-cilisis port- mi, in consequ-t di-m euismod quis. Pellentesque h-bit-nt morbi tristique senectus et netus et m-lesu-d- f-mes -c turpis egest-s.
|
2
|
+
|
3
|
+
Aliqu-m et enim nec er-t i-culis m-lesu-d- eu - nisl. Proin commodo commodo luctus. Sed in qu-m et s-pien sollicitudin bibendum. N-m eget i-culis elit. Ph-sellus ligul- nunc, tempor id tristique quis, pellentesque quis m-uris. Sed hendrerit i-culis dolor, nec pellentesque lectus volutp-t -t. Nunc vehicul- null- et er-t orn-re quis bl-ndit di-m imperdiet. In i-culis lectus orci. Cl-ss -ptent t-citi sociosqu -d litor- torquent per conubi- nostr-, per inceptos himen-eos. Vestibulum sod-les tincidunt ipsum, nec s-gittis nisl s-gittis non. Proin eget urn- - qu-m dictum orn-re eu vit-e l-cus. Aliqu-m er-t volutp-t. Null- -ccums-n tristique qu-m, et mollis dui gr-vid- ut.
|
@@ -0,0 +1,3 @@
|
|
1
|
+
L-r-m -ps-m d-l-r s-t -m-t, c-ns-ct-t-r -d-p-sc-ng -l-t. N-ll-m n-q-- -st, -rn-r- s-t -m-t f-c-l-s-s n-n, v-v-rr- -t r-s-s. F-sc- n-bh l-ct-s, -d-p-sc-ng -t c-ns-q--t -g-t, f--c-b-s s-d -r-t. V-st-b-l-m n-c q--m l-ct-s. V-st-b-l-m -l--f-nd d-p-b-s l--. M--c-n-s -n t-ll-s m-ss-. M--r-s -n l-- v-l s-m s-sc-p-t c-ng--. In -- n-bh -d l-b-r- p-s--r- --ct-r. S-sp-nd-ss- m-tt-s m- -n n-bh gr-v-d- sc-l-r-sq--. N-ll-m -n r-s-s l-r-m. Q--sq-- t-rp-s s-m, ph-r-tr- -g-t c-nv-ll-s n-c, v-l-tp-t -t -st. D--s n-n -rn- t-rt-r, s-t -m-t -nt-rd-m f-l-s. Et--m v-t-- m-t-s -t t-rp-s v-v-rr- ---sm-d -- s-d p-r-s. In l--r--t d--m v-l n-q-- s-g-tt-s p-rt- m-tt-s -ps-m v-l-tp-t. Pr--s-nt m-l-s--d- d-- n-c n-q-- pl-c-r-t -d ph-r-tr- -l-t s-ll-c-t-d-n. Pr--n t-ll-s -rc-, t-nc-d-nt -t -ll-mc-rp-r --, l-b-rt-s -c t-rt-r. Al-q--m --c-l-s d-l-r -c -d-- f-rm-nt-m -g-t l-b-rt-s l-r-m d-gn-ss-m. N-ll- f-c-l-s-s p-rt- m-, -n c-ns-q--t d--m ---sm-d q--s. P-ll-nt-sq-- h-b-t-nt m-rb- tr-st-q-- s-n-ct-s -t n-t-s -t m-l-s--d- f-m-s -c t-rp-s -g-st-s.
|
2
|
+
|
3
|
+
Al-q--m -t -n-m n-c -r-t --c-l-s m-l-s--d- -- - n-sl. Pr--n c-mm-d- c-mm-d- l-ct-s. S-d -n q--m -t s-p--n s-ll-c-t-d-n b-b-nd-m. N-m -g-t --c-l-s -l-t. Ph-s-ll-s l-g-l- n-nc, t-mp-r -d tr-st-q-- q--s, p-ll-nt-sq-- q--s m--r-s. S-d h-ndr-r-t --c-l-s d-l-r, n-c p-ll-nt-sq-- l-ct-s v-l-tp-t -t. N-nc v-h-c-l- n-ll- -t -r-t -rn-r- q--s bl-nd-t d--m -mp-rd--t. In --c-l-s l-ct-s -rc-. Cl-ss -pt-nt t-c-t- s-c--sq- -d l-t-r- t-rq--nt p-r c-n-b-- n-str-, p-r -nc-pt-s h-m-n---s. V-st-b-l-m s-d-l-s t-nc-d-nt -ps-m, n-c s-g-tt-s n-sl s-g-tt-s n-n. Pr--n -g-t -rn- - q--m d-ct-m -rn-r- -- v-t-- l-c-s. Al-q--m -r-t v-l-tp-t. N-ll- -cc-ms-n tr-st-q-- q--m, -t m-ll-s d-- gr-v-d- -t.
|
data/test/runner_test.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class RunnerTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_dsl
|
6
|
+
Sed::Commander.expects(:replace).with(
|
7
|
+
'input.txt',
|
8
|
+
'expression',
|
9
|
+
'replacement',
|
10
|
+
'OPTS'
|
11
|
+
)
|
12
|
+
|
13
|
+
Sed::Commander.expects(:replace).with(
|
14
|
+
'input.txt',
|
15
|
+
'expression2',
|
16
|
+
'replacement2',
|
17
|
+
'OPTS'
|
18
|
+
)
|
19
|
+
|
20
|
+
Sed::Runner.new('input.txt', 'OPTS') do |s|
|
21
|
+
s.replace('expression', 'replacement')
|
22
|
+
s.replace('expression2', 'replacement2')
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/util_test.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class UtilTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_system_osx
|
6
|
+
Sed::Util.instance_variable_set(:@system, nil)
|
7
|
+
Kernel.expects(:system).with("sed --version 2> /dev/null").returns(false)
|
8
|
+
assert_equal(:osx, Sed::Util.system)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_system_gnu
|
12
|
+
Sed::Util.instance_variable_set(:@system, nil)
|
13
|
+
Kernel.expects(:system).with("sed --version 2> /dev/null").returns(true)
|
14
|
+
assert_equal(:gnu, Sed::Util.system)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_osx
|
18
|
+
Sed::Util.expects(:system).returns(:osx)
|
19
|
+
assert(Sed::Util.osx?)
|
20
|
+
|
21
|
+
Sed::Util.expects(:system).returns(:gnu)
|
22
|
+
assert(!Sed::Util.osx?)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_gnu
|
26
|
+
Sed::Util.expects(:system).returns(:osx)
|
27
|
+
assert(!Sed::Util.gnu?)
|
28
|
+
|
29
|
+
Sed::Util.expects(:system).returns(:gnu)
|
30
|
+
assert(Sed::Util.gnu?)
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Fernando Guillen (http://fernandoguillen.info)
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-06-06 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- rc
|
33
|
+
- 6
|
34
|
+
version: 1.0.0.rc.6
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Use the `sed` command from Ruby code
|
38
|
+
email:
|
39
|
+
- fguillen.mail@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- .rvmrc.example
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- examples/examples.rb
|
54
|
+
- examples/file.txt
|
55
|
+
- lib/sed.rb
|
56
|
+
- lib/sed/commander.rb
|
57
|
+
- lib/sed/runner.rb
|
58
|
+
- lib/sed/util.rb
|
59
|
+
- lib/sed/version.rb
|
60
|
+
- sed.gemspec
|
61
|
+
- test/commander_test.rb
|
62
|
+
- test/fixtures/input01.txt
|
63
|
+
- test/fixtures/output01.txt
|
64
|
+
- test/fixtures/output01_ere.txt
|
65
|
+
- test/runner_test.rb
|
66
|
+
- test/test_helper.rb
|
67
|
+
- test/util_test.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: https://github.com/fguillen/SedWrapper
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 1
|
92
|
+
- 3
|
93
|
+
- 6
|
94
|
+
version: 1.3.6
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project: sed
|
98
|
+
rubygems_version: 1.3.7
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Wrapper for the Unix shell command `sed`
|
102
|
+
test_files: []
|
103
|
+
|