ix-cli 0.0.6 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ix-bcat +32 -0
- data/bin/ix-cat +5 -5
- data/bin/ix-prepend +8 -0
- data/bin/ix-rot13 +7 -2
- data/bin/ix-rot5 +39 -0
- data/bin/ix-string-similarity +178 -108
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb14cdf843c9b38f5aa771f23334ee0bb58ebcc6cd138c56ce2af5d02fbe283d
|
4
|
+
data.tar.gz: b09c43e5a377df98063a481d8ccefc95ee698b5fbee9416e95e5e9b6e19eb9bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daef124c711c4365df35f28c2366c8f0cab9a3e83110eb2574ccee83298fef06637e1ba183b31a65e4b6c03a79f412cc9308f2fd0769d74d01fa2d078d48e0d1
|
7
|
+
data.tar.gz: 16807bada66a3cbd525e2cdb7b5726e9b2457bb05b392dbabde129d42e6f808309c6b065a6fa1c4f72a222a55952bc551ec4a35ef51edef49bb33e29b8c37223
|
data/bin/ix-bcat
CHANGED
@@ -175,10 +175,42 @@ class Bcat
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
+
require 'optparse'
|
179
|
+
|
180
|
+
options = {}
|
181
|
+
|
182
|
+
OptionParser.new do |opts|
|
183
|
+
|
184
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
185
|
+
|
186
|
+
opts.on('-p', '--pre', 'Pre.') do |value|
|
187
|
+
options[:pre] = value
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
end.parse!
|
192
|
+
|
193
|
+
required_options = []
|
194
|
+
required_options.each do |option|
|
195
|
+
unless options[option]
|
196
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
197
|
+
exit 1
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
178
201
|
data = []
|
179
202
|
|
180
203
|
STDIN.each_line do |line|
|
181
204
|
data.push(line)
|
182
205
|
end
|
183
206
|
|
207
|
+
if options[:pre]
|
208
|
+
puts '<pre>'
|
209
|
+
end
|
210
|
+
|
184
211
|
puts Bcat::ANSI.new(data).to_html
|
212
|
+
|
213
|
+
if options[:pre]
|
214
|
+
puts '</pre>'
|
215
|
+
end
|
216
|
+
|
data/bin/ix-cat
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
#!/usr/bin/env
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
application
|
4
|
-
target_path
|
5
|
-
target_file="
|
3
|
+
application = ARGV[0]
|
4
|
+
target_path = File.dirname(__FILE__)
|
5
|
+
target_file = "#{target_path}/ix-#{application}"
|
6
6
|
|
7
|
-
cat
|
7
|
+
system "cat #{target_file}"
|
data/bin/ix-prepend
ADDED
data/bin/ix-rot13
CHANGED
@@ -3,7 +3,12 @@
|
|
3
3
|
normal = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
4
4
|
rot13 = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"
|
5
5
|
|
6
|
-
STDIN.
|
7
|
-
|
6
|
+
STDIN.each_char do |char|
|
7
|
+
candidate = char.tr!(normal, rot13)
|
8
|
+
if candidate
|
9
|
+
print candidate
|
10
|
+
else
|
11
|
+
print char
|
12
|
+
end
|
8
13
|
end
|
9
14
|
|
data/bin/ix-rot5
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'isna'
|
4
|
+
|
5
|
+
UNIVERSE = (0..9).to_a
|
6
|
+
ROT = 5
|
7
|
+
DIGIT_REGEX = /^\d$/
|
8
|
+
|
9
|
+
def resolve(set, candidate)
|
10
|
+
needle = set.index(candidate)
|
11
|
+
if (needle + ROT) > set.size
|
12
|
+
return (needle - set.size + ROT)
|
13
|
+
end
|
14
|
+
if (needle + ROT) < set.size
|
15
|
+
return needle + ROT
|
16
|
+
end
|
17
|
+
if (needle == 5)
|
18
|
+
return 0
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
STDIN.each_char do |char|
|
23
|
+
next if char.chomp == ''
|
24
|
+
unless char =~ DIGIT_REGEX
|
25
|
+
print char
|
26
|
+
next
|
27
|
+
end
|
28
|
+
rotation = resolve(UNIVERSE, char.to_i)
|
29
|
+
m = (0..9).to_a.map do |n|
|
30
|
+
if n.to_s == char
|
31
|
+
char.to_ansi.green.to_s
|
32
|
+
else
|
33
|
+
n.to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
# puts "#{rotation.to_s.to_ansi.red.to_s} = [" + (m * ', ') + "]"
|
37
|
+
print rotation
|
38
|
+
end
|
39
|
+
|
data/bin/ix-string-similarity
CHANGED
@@ -1,152 +1,222 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
class Chunk
|
4
|
+
attr_accessor :char_1
|
5
|
+
attr_accessor :char_2
|
6
|
+
attr_accessor :index_1
|
7
|
+
attr_accessor :index_2
|
8
|
+
|
9
|
+
def initialize(c1, c2, i1, i2)
|
10
|
+
@char_1 = c1
|
11
|
+
@char_2 = c2
|
12
|
+
@index_1 = i1
|
13
|
+
@index_2 = i2
|
14
|
+
end
|
5
15
|
|
6
|
-
|
16
|
+
def to_s
|
17
|
+
"#{char_1} #{char_2} #{index_1} #{index_2}"
|
18
|
+
end
|
19
|
+
end
|
7
20
|
|
8
|
-
|
21
|
+
class Similarity
|
22
|
+
CHAR_REGEX = /./
|
9
23
|
|
10
|
-
|
11
|
-
|
12
|
-
opts.separator "Usage: #{File.basename($0)} [OPTIONS]"
|
13
|
-
opts.separator ''
|
24
|
+
attr_accessor :string_1
|
25
|
+
attr_accessor :string_2
|
14
26
|
|
15
|
-
|
16
|
-
|
17
|
-
|
27
|
+
def initialize(string_1, string_2)
|
28
|
+
@string_1 = string_1
|
29
|
+
@string_2 = string_2
|
30
|
+
end
|
18
31
|
|
19
|
-
|
20
|
-
|
21
|
-
|
32
|
+
def tokens
|
33
|
+
chunks = []
|
34
|
+
string_1.scan(CHAR_REGEX).each_with_index do |char_1, index_1|
|
35
|
+
string_2.scan(CHAR_REGEX).each_with_index do |char_2, index_2|
|
36
|
+
next if char_1 != char_2
|
37
|
+
chunks.push(Chunk.new(char_1, char_2, index_1, index_2))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
chunks
|
22
41
|
end
|
23
42
|
|
24
|
-
|
25
|
-
|
26
|
-
|
43
|
+
def count
|
44
|
+
counter = 0
|
45
|
+
prev = false
|
46
|
+
tokens.each_with_index do |chunk, index|
|
47
|
+
|
48
|
+
unless prev
|
49
|
+
prev = chunk.index_1
|
50
|
+
next
|
51
|
+
end
|
52
|
+
|
53
|
+
if prev == (chunk.index_1 - 1)
|
54
|
+
counter += 1
|
55
|
+
end
|
56
|
+
|
57
|
+
prev = chunk.index_1
|
58
|
+
end
|
59
|
+
|
60
|
+
counter
|
27
61
|
end
|
28
62
|
|
29
|
-
|
30
|
-
|
31
|
-
|
63
|
+
def score
|
64
|
+
desired = (string_1.size + string_2.size) / 2
|
65
|
+
size_thresh = ([string_1.size, string_2.size].sort.first.to_f / desired)
|
66
|
+
compatibility_thresh = (count.to_f + 1) / string_1.size
|
67
|
+
(size_thresh + compatibility_thresh).to_f / 2
|
32
68
|
end
|
69
|
+
end
|
70
|
+
|
71
|
+
require 'optparse'
|
72
|
+
|
73
|
+
options = {}
|
74
|
+
options[:threshold] = 0.8
|
33
75
|
|
76
|
+
OptionParser.new do |opts|
|
34
77
|
|
35
|
-
opts.
|
78
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
79
|
+
|
80
|
+
opts.on('-t', '--threshold [NUMBER]', 'Threshold default value is 0.8.') do |value|
|
81
|
+
options[:threshold] = value.to_f
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on('-s', '--summary', 'Print Summarized version.') do |value|
|
85
|
+
options[:summary] = value
|
86
|
+
end
|
36
87
|
|
37
88
|
end.parse!
|
38
89
|
|
39
|
-
|
90
|
+
required_options = [:threshold]
|
91
|
+
required_options.each do |option|
|
92
|
+
unless options[option]
|
93
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
94
|
+
exit 1
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# hash = {
|
99
|
+
# 'line' => [
|
100
|
+
# { :line => 'line', :score => 1 },
|
101
|
+
# ]
|
102
|
+
# }
|
103
|
+
|
104
|
+
hash = {}
|
105
|
+
lines = 0
|
40
106
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
107
|
+
STDIN.each_line do |line|
|
108
|
+
line.chomp!
|
109
|
+
next if line == ''
|
110
|
+
lines += 1
|
111
|
+
resolved = false
|
112
|
+
hash.keys.each do |registered_line|
|
113
|
+
score = Similarity.new(line, registered_line).score
|
114
|
+
if score > options[:threshold]
|
115
|
+
hash[registered_line].push({
|
116
|
+
:line => line,
|
117
|
+
:score => score
|
118
|
+
})
|
119
|
+
resolved = true
|
45
120
|
end
|
46
121
|
end
|
122
|
+
next if resolved
|
123
|
+
hash[line] ||= []
|
47
124
|
end
|
48
125
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
126
|
+
module Template
|
127
|
+
|
128
|
+
class Banner < Struct.new(:lines, :groups, :threshold, :datetime)
|
129
|
+
def to_s
|
130
|
+
format(template, to_h)
|
131
|
+
end
|
132
|
+
def template
|
133
|
+
'
|
134
|
+
Total Lines Parsed: %<lines>s
|
135
|
+
Total Groups Generated: %<groups>s
|
136
|
+
Similarity Theshold at: %<threshold>s
|
137
|
+
Generated on: %<datetime>s
|
138
|
+
'
|
54
139
|
end
|
55
|
-
array
|
56
140
|
end
|
57
141
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
longest_string = other_string
|
62
|
-
shortest_string = self
|
63
|
-
else
|
64
|
-
longest_string = self
|
65
|
-
shortest_string = other_string
|
66
|
-
end
|
67
|
-
scores = longest_string.to_a.map do |char|
|
68
|
-
0
|
142
|
+
class Group < Struct.new(:number, :percent, :items, :line)
|
143
|
+
def to_s
|
144
|
+
format(template, to_h)
|
69
145
|
end
|
70
|
-
|
71
|
-
|
72
|
-
scores[index] = 1
|
73
|
-
end
|
146
|
+
def template
|
147
|
+
'Group %<number>s represents %<percent>s and has %<items>s items similar to: %<line>s'
|
74
148
|
end
|
75
|
-
scores
|
76
149
|
end
|
77
150
|
|
78
|
-
|
79
|
-
|
151
|
+
class Item < Struct.new(:count, :total, :score, :line)
|
152
|
+
def to_s
|
153
|
+
format(template, to_h)
|
154
|
+
end
|
155
|
+
def template
|
156
|
+
' %<count>s/%<total>s %<score>s %<line>s'
|
157
|
+
end
|
80
158
|
end
|
81
|
-
end
|
82
159
|
|
83
|
-
class TargetString
|
84
|
-
attr_accessor :evaluated
|
85
|
-
attr_accessor :data
|
86
|
-
def to_s
|
87
|
-
data
|
88
|
-
end
|
89
160
|
end
|
90
161
|
|
91
|
-
|
162
|
+
require 'isna'
|
92
163
|
|
93
|
-
|
164
|
+
summary_output = []
|
165
|
+
detailed_output = []
|
94
166
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
167
|
+
banner = Template::Banner.new
|
168
|
+
banner.lines = lines.to_s.to_ansi.yellow.to_s
|
169
|
+
banner.groups = hash.keys.size.to_s.to_ansi.yellow.to_s
|
170
|
+
banner.threshold = options[:threshold].to_s.to_ansi.yellow.to_s
|
171
|
+
banner.datetime = Time.now.to_s.to_ansi.yellow.to_s
|
172
|
+
summary_output.push(banner.to_s)
|
99
173
|
|
100
|
-
|
101
|
-
|
174
|
+
groups = []
|
175
|
+
|
176
|
+
hash.each do |category_name, records|
|
177
|
+
groups.push([category_name, records.size])
|
102
178
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
target_string.evaluated = false
|
109
|
-
target_string.data = string
|
110
|
-
target_string
|
179
|
+
|
180
|
+
sorted_groups_by_n_records_asc = groups.sort do |array_a, array_b|
|
181
|
+
number_of_records_in_a = array_a[1]
|
182
|
+
number_of_records_in_b = array_b[1]
|
183
|
+
number_of_records_in_a <=> number_of_records_in_b
|
111
184
|
end
|
112
185
|
|
113
|
-
|
114
|
-
|
115
|
-
|
186
|
+
sorted_groups_by_n_records_asc.reverse.each_with_index do |key, index|
|
187
|
+
line, records = key[0], hash[key[0]]
|
188
|
+
|
189
|
+
detailed_output.push('')
|
190
|
+
|
191
|
+
group = Template::Group.new
|
192
|
+
group.percent = ('%2.2f%%' % ((records.size.to_f / lines) * 100)).to_s.to_ansi.red.to_s
|
193
|
+
group.number = (index + 1).to_s.to_ansi.red.to_s
|
194
|
+
group.items = records.size.to_s.to_ansi.cyan.to_s
|
195
|
+
group.line = line.chomp.to_ansi.green.to_s
|
196
|
+
summary_output.push(group.to_s)
|
197
|
+
detailed_output.push(group.to_s)
|
198
|
+
|
199
|
+
sorted_items_in_group = records.sort do |a, b|
|
200
|
+
a[:score] <=> b[:score]
|
116
201
|
end
|
117
|
-
else
|
118
|
-
groups = { 0 => strings }
|
119
|
-
end
|
120
202
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
else
|
129
|
-
puts "****>>" + string_1.to_s
|
130
|
-
end
|
131
|
-
end
|
132
|
-
string_1.evaluated = true
|
133
|
-
group.each do |string_2|
|
134
|
-
next if string_2.evaluated
|
135
|
-
similarity = string_1.to_s.similarity(string_2.to_s)
|
136
|
-
scores = string_1.to_s.scores(string_2.to_s).inspect
|
137
|
-
template = "%5.f %s"
|
138
|
-
bindings = [similarity, string_2, scores]
|
139
|
-
if similarity >= configuration.threshold
|
140
|
-
string_2.evaluated = true
|
141
|
-
counter += 1
|
142
|
-
unless configuration.summary
|
143
|
-
puts template % bindings
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
if counter > 0
|
148
|
-
puts "#{counter} #{summary_string}"
|
149
|
-
end
|
203
|
+
sorted_items_in_group.reverse.each_with_index do |record, index|
|
204
|
+
item = Template::Item.new
|
205
|
+
item.count = (index + 1).to_s.rjust(4, ' ').to_ansi.cyan.to_s
|
206
|
+
item.total = records.size.to_s.ljust(4, ' ').to_ansi.cyan.to_s
|
207
|
+
item.score = ('%4.2f%%' % (record[:score] * 100)).rjust(7, ' ').to_ansi.green.to_s
|
208
|
+
item.line = record[:line]
|
209
|
+
detailed_output.push(item.to_s)
|
150
210
|
end
|
211
|
+
|
151
212
|
end
|
152
213
|
|
214
|
+
summary_output.each do |output_line|
|
215
|
+
puts output_line
|
216
|
+
end
|
217
|
+
|
218
|
+
unless options[:summary]
|
219
|
+
detailed_output.each do |output_line|
|
220
|
+
puts output_line
|
221
|
+
end
|
222
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ix-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuyoshi Tlacaelel
|
@@ -199,6 +199,7 @@ executables:
|
|
199
199
|
- ix-pick
|
200
200
|
- ix-planning-tickets
|
201
201
|
- ix-prefix
|
202
|
+
- ix-prepend
|
202
203
|
- ix-pretty
|
203
204
|
- ix-print-and-run
|
204
205
|
- ix-psd-to-json
|
@@ -217,6 +218,7 @@ executables:
|
|
217
218
|
- ix-reverse
|
218
219
|
- ix-right
|
219
220
|
- ix-rm
|
221
|
+
- ix-rot5
|
220
222
|
- ix-rot13
|
221
223
|
- ix-rot3
|
222
224
|
- ix-rps
|
@@ -477,6 +479,7 @@ files:
|
|
477
479
|
- bin/ix-pick
|
478
480
|
- bin/ix-planning-tickets
|
479
481
|
- bin/ix-prefix
|
482
|
+
- bin/ix-prepend
|
480
483
|
- bin/ix-pretty
|
481
484
|
- bin/ix-print-and-run
|
482
485
|
- bin/ix-psd-to-json
|
@@ -497,6 +500,7 @@ files:
|
|
497
500
|
- bin/ix-rm
|
498
501
|
- bin/ix-rot13
|
499
502
|
- bin/ix-rot3
|
503
|
+
- bin/ix-rot5
|
500
504
|
- bin/ix-rps
|
501
505
|
- bin/ix-ruby-constructor-arguments
|
502
506
|
- bin/ix-ruby-methods
|