tefil 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.
- checksums.yaml +4 -4
- data/CHANGES +6 -1
- data/VERSION +1 -1
- data/bin/calc +27 -0
- data/bin/linesub +4 -3
- data/lib/tefil/calculator.rb +48 -0
- data/lib/tefil/eachsentence.rb +2 -2
- data/lib/tefil/linesubstituter.rb +3 -2
- data/lib/tefil/percentpacker.rb +1 -2
- data/lib/tefil.rb +1 -0
- data/tefil.gemspec +8 -4
- data/test/calc/sample.dat +10 -0
- data/test/test_calculator.rb +67 -0
- data/test/test_fswikitomd.rb +1 -1
- data/test/test_indentconverter.rb +1 -1
- data/test/test_indentstatistics.rb +1 -1
- data/test/test_linesubstituter.rb +17 -4
- data/test/test_mdtofswiki.rb +1 -1
- data/test/test_percentpacker.rb +1 -1
- data/test/test_textfilterbase.rb +1 -1
- data/test/test_zshescaper.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3ef66ea997858ff83884169a599185c467dd4c7
|
4
|
+
data.tar.gz: 66190e623c8c877207106ca7c786b4af25502e93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e145abcfdf2cbe51c02f2a2f3ba94f86ce89cdda1ccbac22d909842fe3d5fb6675237442f408a85169cec5de457495f98225821abd38fb91de3a1a09fa5b44de
|
7
|
+
data.tar.gz: 3786672cd4ebaef84982f497941a24cde3705fed3f77755b1d3b5765cc5646ddecf1c7ca0473ff41a20eb7d8f6f304430758aa711480e7ec801cc2bc77ded4ce
|
data/CHANGES
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
= tefil changelog
|
2
2
|
|
3
|
-
== Master (for 0.1.
|
3
|
+
== Master (for 0.1.3)
|
4
|
+
|
5
|
+
== Version 0.1.2 [2016-04-27] released
|
6
|
+
* Add bin/calc
|
7
|
+
* Add 'bin/linesub --regexp' option
|
8
|
+
* Adjust to Ruby2.3
|
4
9
|
|
5
10
|
== Version 0.1.1 [2016-03-11] released
|
6
11
|
* Add bin/eachsentence
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/bin/calc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
#
|
4
|
+
# USAGE: calc [options] str0 str1 files ...
|
5
|
+
|
6
|
+
require "pp"
|
7
|
+
require "optparse"
|
8
|
+
#require "rubygems"
|
9
|
+
#require "tempfile"
|
10
|
+
require "tefil"
|
11
|
+
|
12
|
+
## option analysis
|
13
|
+
options = {}
|
14
|
+
op = OptionParser.new
|
15
|
+
op.banner = [
|
16
|
+
"Usage: #{File.basename("#{__FILE__}")} old_str new_str [options] [files]",
|
17
|
+
].join("\n")
|
18
|
+
op.on("-o" , "--overwrite" , "Overwrite."){ options[:overwrite] = true}
|
19
|
+
op.on("-g" , "--global" , "Globally substitute."){ options[:global] = true}
|
20
|
+
op.on("-p" , "--preserve" , "Preserve equation with '='."){ options[:preserve] = true}
|
21
|
+
op.on("-r" , "--ruby" , "Use Ruby 'eval' in spite of 'bc -l', powerful but security weakness."){ options[:ruby] = true} #Math::PI や実数乗ができる。
|
22
|
+
op.parse!(ARGV)
|
23
|
+
|
24
|
+
options[:overwrite] ||= false
|
25
|
+
|
26
|
+
tf = Tefil::Calculator.new(options)
|
27
|
+
tf.filter(ARGV)
|
data/bin/linesub
CHANGED
@@ -14,10 +14,11 @@ require "tefil.rb"
|
|
14
14
|
options = {}
|
15
15
|
op = OptionParser.new
|
16
16
|
op.banner = [
|
17
|
-
"Usage: #{File.basename("#{__FILE__}")} old_str new_str [
|
17
|
+
"Usage: #{File.basename("#{__FILE__}")} [options] old_str new_str [files]",
|
18
18
|
].join("\n")
|
19
|
-
op.on("-o" , "--overwrite" , "Overwrite
|
20
|
-
op.on("-g" , "--global" , "Globally substitute
|
19
|
+
op.on("-o" , "--overwrite" , "Overwrite"){ options[:overwrite] = true}
|
20
|
+
op.on("-g" , "--global" , "Globally substitute"){ options[:global] = true}
|
21
|
+
op.on("-r" , "--reg-exp" , "Regular expression for old_str"){ options[:regexp] = true}
|
21
22
|
op.parse!(ARGV)
|
22
23
|
|
23
24
|
old_str = ARGV.shift
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
class Tefil::Calculator < Tefil::TextFilterBase
|
9
|
+
def initialize(options = {})
|
10
|
+
@options = options
|
11
|
+
@preserve = options[:preserve]
|
12
|
+
@ruby = options[:ruby]
|
13
|
+
super(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def process_stream(in_io, out_io)
|
17
|
+
in_io.each do |line|
|
18
|
+
eq = line.chomp
|
19
|
+
|
20
|
+
eq.gsub!(/\{/, '(' )
|
21
|
+
eq.gsub!(/\}/, ')' )
|
22
|
+
eq.gsub!(/\\times/, '*' )
|
23
|
+
|
24
|
+
if @ruby
|
25
|
+
eq.gsub!(/\^/, '**' )
|
26
|
+
eq.gsub!(/sqrt/, 'Math::sqrt' )
|
27
|
+
eq.gsub!(/log\(/, 'Math::log(' )
|
28
|
+
eq.gsub!(/l\(/, 'Math::log(' )
|
29
|
+
eq.gsub!(/exp\(/, 'Math::exp(' )
|
30
|
+
eq.gsub!(/e\(/, 'Math::exp(' )
|
31
|
+
result = eval(eq)
|
32
|
+
else
|
33
|
+
eq.gsub!(/\(/, '\(' )
|
34
|
+
eq.gsub!(/\)/, '\)' )
|
35
|
+
eq.gsub!(/\*/, '\*' )
|
36
|
+
|
37
|
+
result = `echo #{eq} | bc -l`.chomp
|
38
|
+
result.sub!(/^\./, '0.')
|
39
|
+
result.sub!(/^-\./, '-0.')
|
40
|
+
result.sub!(/^0$/, '0.0')
|
41
|
+
end
|
42
|
+
|
43
|
+
out_io.print line.chomp + " = " if @preserve
|
44
|
+
out_io.puts result
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/lib/tefil/eachsentence.rb
CHANGED
@@ -12,11 +12,11 @@ class Tefil::EachSentence < Tefil::TextFilterBase
|
|
12
12
|
|
13
13
|
def process_stream(in_io, out_io)
|
14
14
|
results = []
|
15
|
-
words = []
|
15
|
+
#words = []
|
16
16
|
in_io.read.strip.split("\n").each do |line|
|
17
17
|
new_line = ''
|
18
18
|
#line.gsub!("\n", ' ')
|
19
|
-
line.chars do |char|
|
19
|
+
line.chars.each do |char|
|
20
20
|
new_line += char
|
21
21
|
new_line += "\n" if (END_CHAR.include?(char))
|
22
22
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class Tefil::LineSubstituter < Tefil::TextFilterBase
|
2
2
|
def initialize(old_str, new_str, options = {})
|
3
|
-
@old_str = old_str
|
4
|
-
@
|
3
|
+
@old_str = old_str
|
4
|
+
@old_str = /#{old_str}/ if options[:regexp]
|
5
|
+
@new_str = new_str
|
5
6
|
@global = options[:global]
|
6
7
|
super(options)
|
7
8
|
end
|
data/lib/tefil/percentpacker.rb
CHANGED
@@ -2,13 +2,12 @@ class Tefil::PercentPacker < Tefil::TextFilterBase
|
|
2
2
|
def process_stream(in_io, out_io)
|
3
3
|
in_io.each do |line|
|
4
4
|
old_chars = line.split("")
|
5
|
-
|
6
5
|
new_str = ""
|
7
6
|
new_index = 0
|
8
7
|
old_index = 0
|
9
8
|
while old_index < old_chars.size
|
10
9
|
if old_chars[old_index] == "%"
|
11
|
-
new_str += [old_chars[(old_index +1) .. (old_index + 2)].join].pack("H*")
|
10
|
+
new_str += [old_chars[(old_index + 1) .. (old_index + 2)].join].pack("H*")
|
12
11
|
old_index += 2
|
13
12
|
else
|
14
13
|
new_str += old_chars[old_index]
|
data/lib/tefil.rb
CHANGED
data/tefil.gemspec
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: tefil 0.1.
|
5
|
+
# stub: tefil 0.1.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "tefil"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["ippei94da"]
|
14
|
-
s.date = "2016-
|
14
|
+
s.date = "2016-04-27"
|
15
15
|
s.description = "This gem provides a framework of text filter.\n Tefil eneable to make text filter commands which have overwrite option easily.\n "
|
16
16
|
s.email = "ippei94da@gmail.com"
|
17
|
-
s.executables = ["columnform", "eachsentence", "fswiki2md", "indentconv", "indentstat", "linesub", "md2fswiki", "percentpack", "zshescape"]
|
17
|
+
s.executables = ["calc", "columnform", "eachsentence", "fswiki2md", "indentconv", "indentstat", "linesub", "md2fswiki", "percentpack", "zshescape"]
|
18
18
|
s.extra_rdoc_files = [
|
19
19
|
"LICENSE.txt",
|
20
20
|
"README.rdoc"
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"README.rdoc",
|
28
28
|
"Rakefile",
|
29
29
|
"VERSION",
|
30
|
+
"bin/calc",
|
30
31
|
"bin/columnform",
|
31
32
|
"bin/eachsentence",
|
32
33
|
"bin/fswiki2md",
|
@@ -47,6 +48,7 @@ Gem::Specification.new do |s|
|
|
47
48
|
"example/percentpack/sample.txt",
|
48
49
|
"example/zshescape/sample.txt",
|
49
50
|
"lib/tefil.rb",
|
51
|
+
"lib/tefil/calculator.rb",
|
50
52
|
"lib/tefil/columnformer.rb",
|
51
53
|
"lib/tefil/eachsentence.rb",
|
52
54
|
"lib/tefil/fswikitomd.rb",
|
@@ -58,8 +60,10 @@ Gem::Specification.new do |s|
|
|
58
60
|
"lib/tefil/textfilterbase.rb",
|
59
61
|
"lib/tefil/zshescaper.rb",
|
60
62
|
"tefil.gemspec",
|
63
|
+
"test/calc/sample.dat",
|
61
64
|
"test/formcolumn_space",
|
62
65
|
"test/helper.rb",
|
66
|
+
"test/test_calculator.rb",
|
63
67
|
"test/test_columnformer.rb",
|
64
68
|
"test/test_eachsentence.rb",
|
65
69
|
"test/test_fswikitomd.rb",
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
require "helper"
|
5
|
+
require "stringio"
|
6
|
+
|
7
|
+
class Tefil::Calculator
|
8
|
+
public :process_stream
|
9
|
+
end
|
10
|
+
|
11
|
+
class TC_Calculator < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
@is00 = Tefil::Calculator.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_process_stream
|
17
|
+
setup
|
18
|
+
$stdin = StringIO.new
|
19
|
+
$stdin.puts "1+2"
|
20
|
+
$stdin.puts "0.1"
|
21
|
+
$stdin.puts "-0.1"
|
22
|
+
$stdin.puts "0.0"
|
23
|
+
$stdin.rewind
|
24
|
+
str = capture_stdout{}
|
25
|
+
result = capture_stdout{ @is00.filter([])}
|
26
|
+
correct =
|
27
|
+
"3\n" +
|
28
|
+
"0.1\n" +
|
29
|
+
"-0.1\n" +
|
30
|
+
"0.0\n"
|
31
|
+
assert_equal(correct, result)
|
32
|
+
|
33
|
+
setup
|
34
|
+
$stdin = StringIO.new
|
35
|
+
$stdin.puts "2^3"
|
36
|
+
$stdin.rewind
|
37
|
+
str = capture_stdout{}
|
38
|
+
result = capture_stdout{ @is00.filter([])}
|
39
|
+
correct = "8\n"
|
40
|
+
assert_equal(correct, result)
|
41
|
+
|
42
|
+
setup
|
43
|
+
$stdin = StringIO.new
|
44
|
+
$stdin.puts "2^{1+2}"
|
45
|
+
$stdin.rewind
|
46
|
+
str = capture_stdout{}
|
47
|
+
result = capture_stdout{ @is00.filter([])}
|
48
|
+
correct = "8\n"
|
49
|
+
assert_equal(correct, result)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
#なぜか変換されないが、コマンド経由ならいける。
|
54
|
+
#def test_times
|
55
|
+
# setup
|
56
|
+
# $stdin = StringIO.new
|
57
|
+
# $stdin.puts "2 \times 3"
|
58
|
+
# $stdin.rewind
|
59
|
+
# str = capture_stdout{}
|
60
|
+
# result = capture_stdout{ @is00.filter([])}
|
61
|
+
# correct = "6\n"
|
62
|
+
# assert_equal(correct, result)
|
63
|
+
#end
|
64
|
+
|
65
|
+
|
66
|
+
end
|
67
|
+
|
data/test/test_fswikitomd.rb
CHANGED
@@ -40,7 +40,7 @@ class TC_FswikiToMd < Test::Unit::TestCase
|
|
40
40
|
$stdin = StringIO.new
|
41
41
|
$stdin.puts i[0]
|
42
42
|
$stdin.rewind
|
43
|
-
str = capture_stdout{}
|
43
|
+
#str = capture_stdout{}
|
44
44
|
result = capture_stdout{ @f00.filter([])}
|
45
45
|
correct = sprintf("#{i[1]}\n")
|
46
46
|
assert_equal(correct, result)
|
@@ -10,8 +10,9 @@ end
|
|
10
10
|
|
11
11
|
class TC_LineSubstituter < Test::Unit::TestCase
|
12
12
|
def setup
|
13
|
-
@
|
14
|
-
@
|
13
|
+
@ls00 = Tefil::LineSubstituter.new('abc', 'XYZ')
|
14
|
+
@ls01 = Tefil::LineSubstituter.new('abc', 'XYZ', {:global => true})
|
15
|
+
@ls02 = Tefil::LineSubstituter.new('^a', 'A', {:regexp => true})
|
15
16
|
end
|
16
17
|
|
17
18
|
def test_process_stream
|
@@ -21,7 +22,7 @@ class TC_LineSubstituter < Test::Unit::TestCase
|
|
21
22
|
$stdin.puts "ABCDABCD"
|
22
23
|
$stdin.rewind
|
23
24
|
str = capture_stdout{}
|
24
|
-
result = capture_stdout{ @
|
25
|
+
result = capture_stdout{ @ls00.filter([])}
|
25
26
|
correct =
|
26
27
|
"XYZdabcd\n" +
|
27
28
|
"ABCDABCD\n"
|
@@ -34,12 +35,24 @@ class TC_LineSubstituter < Test::Unit::TestCase
|
|
34
35
|
$stdin.puts "ABCDABCD"
|
35
36
|
$stdin.rewind
|
36
37
|
str = capture_stdout{}
|
37
|
-
result = capture_stdout{ @
|
38
|
+
result = capture_stdout{ @ls01.filter([])}
|
38
39
|
correct =
|
39
40
|
"XYZdXYZd\n" +
|
40
41
|
"ABCDABCD\n"
|
41
42
|
assert_equal(correct, result)
|
42
43
|
|
44
|
+
setup
|
45
|
+
$stdin = StringIO.new
|
46
|
+
$stdin.puts "abcdabcd"
|
47
|
+
$stdin.puts "ABCDABCD"
|
48
|
+
$stdin.rewind
|
49
|
+
str = capture_stdout{}
|
50
|
+
result = capture_stdout{ @ls02.filter([])}
|
51
|
+
correct =
|
52
|
+
"Abcdabcd\n" +
|
53
|
+
"ABCDABCD\n"
|
54
|
+
assert_equal(correct, result)
|
55
|
+
|
43
56
|
end
|
44
57
|
end
|
45
58
|
|
data/test/test_mdtofswiki.rb
CHANGED
@@ -43,7 +43,7 @@ class TC_MdToFswiki < Test::Unit::TestCase
|
|
43
43
|
$stdin = StringIO.new
|
44
44
|
$stdin.puts i[0]
|
45
45
|
$stdin.rewind
|
46
|
-
str = capture_stdout{}
|
46
|
+
#str = capture_stdout{}
|
47
47
|
result = capture_stdout{ @f00.filter([])}
|
48
48
|
correct = sprintf("#{i[1]}\n")
|
49
49
|
assert_equal(correct, result)
|
data/test/test_percentpacker.rb
CHANGED
@@ -18,7 +18,7 @@ class TC_PercentPacker < Test::Unit::TestCase
|
|
18
18
|
$stdin = StringIO.new
|
19
19
|
$stdin.puts '%E3%83%86%E3%82%B9%E3%83%88'
|
20
20
|
$stdin.rewind
|
21
|
-
str = capture_stdout{}
|
21
|
+
#str = capture_stdout{}
|
22
22
|
result = capture_stdout{ @pp00.filter([])}
|
23
23
|
correct = "テスト\n"
|
24
24
|
assert_equal(correct, result)
|
data/test/test_textfilterbase.rb
CHANGED
data/test/test_zshescaper.rb
CHANGED
@@ -18,7 +18,7 @@ class TC_ZshEscaper < Test::Unit::TestCase
|
|
18
18
|
$stdin = StringIO.new
|
19
19
|
$stdin.puts "abcdABCD * * *"
|
20
20
|
$stdin.rewind
|
21
|
-
str = capture_stdout{}
|
21
|
+
#str = capture_stdout{}
|
22
22
|
result = capture_stdout{ @is00.filter([])}
|
23
23
|
correct = 'abcdABCD\ \*\ \*\ \*' + "\n"
|
24
24
|
assert_equal(correct, result)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tefil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ippei94da
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -112,6 +112,7 @@ description: "This gem provides a framework of text filter.\n Tefil eneable t
|
|
112
112
|
make text filter commands which have overwrite option easily.\n "
|
113
113
|
email: ippei94da@gmail.com
|
114
114
|
executables:
|
115
|
+
- calc
|
115
116
|
- columnform
|
116
117
|
- eachsentence
|
117
118
|
- fswiki2md
|
@@ -133,6 +134,7 @@ files:
|
|
133
134
|
- README.rdoc
|
134
135
|
- Rakefile
|
135
136
|
- VERSION
|
137
|
+
- bin/calc
|
136
138
|
- bin/columnform
|
137
139
|
- bin/eachsentence
|
138
140
|
- bin/fswiki2md
|
@@ -153,6 +155,7 @@ files:
|
|
153
155
|
- example/percentpack/sample.txt
|
154
156
|
- example/zshescape/sample.txt
|
155
157
|
- lib/tefil.rb
|
158
|
+
- lib/tefil/calculator.rb
|
156
159
|
- lib/tefil/columnformer.rb
|
157
160
|
- lib/tefil/eachsentence.rb
|
158
161
|
- lib/tefil/fswikitomd.rb
|
@@ -164,8 +167,10 @@ files:
|
|
164
167
|
- lib/tefil/textfilterbase.rb
|
165
168
|
- lib/tefil/zshescaper.rb
|
166
169
|
- tefil.gemspec
|
170
|
+
- test/calc/sample.dat
|
167
171
|
- test/formcolumn_space
|
168
172
|
- test/helper.rb
|
173
|
+
- test/test_calculator.rb
|
169
174
|
- test/test_columnformer.rb
|
170
175
|
- test/test_eachsentence.rb
|
171
176
|
- test/test_fswikitomd.rb
|