codes21 0.1.2 → 0.2.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 +4 -4
- data/bin/codes21 +28 -4
- data/lib/codes21.rb +15 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 555c03e7f89ac0070403ba3dbf63feabe0b00517
|
4
|
+
data.tar.gz: f7c2a11c2519b46dab69d540e5b3ba87089c7736
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 859345aca9cdac4a6968cfb2e99eafb633d197d9ea041b4c5671d4d616d86c134b9097beef0e0232422a79a24a71867ccedfa232cc3563cef18f6fd3658fd203
|
7
|
+
data.tar.gz: ec14c060a36f175971f7db0f7d2c767eafb8e9336f45766825a62f730cd581a964aafcf992aed15a78d5111682288e8704f157bc7ae4f6ba6bf4d6e1e5464dd2
|
data/bin/codes21
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'optparse'
|
3
4
|
require_relative '../lib/codes21'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
help = <<-HELP
|
7
|
+
With the given suffixes merge multiple files code into one file.
|
8
|
+
usage: codes21 /path/to/project rb,js result.txt [-i UTF-8] [-o UTF-8]
|
9
|
+
HELP
|
10
|
+
|
11
|
+
if ARGV.count < 3
|
12
|
+
puts help
|
8
13
|
exit
|
9
14
|
end
|
10
15
|
|
@@ -12,4 +17,23 @@ path = ARGV[0]
|
|
12
17
|
suffixes = ARGV[1]
|
13
18
|
output = ARGV[2]
|
14
19
|
|
15
|
-
|
20
|
+
input_coding = "UTF-8"
|
21
|
+
output_coding = "UTF-8"
|
22
|
+
|
23
|
+
OptionParser.new do |opts|
|
24
|
+
opts.banner = "usage: codes21 /path/to/project rb,js result.txt [-i=UTF-8] [-o=UTF-8]"
|
25
|
+
opts.on("-iENCODE", "Input file coding") do |coding|
|
26
|
+
input_coding = coding
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-oENCODE", "Output file coding") do |coding|
|
30
|
+
output_coding = coding
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("-h") do
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
|
37
|
+
end.parse!
|
38
|
+
|
39
|
+
Codes21.run path, suffixes, output, input_coding, output_coding
|
data/lib/codes21.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
class Codes21
|
2
|
-
def get_codes(path, suffixes)
|
2
|
+
def get_codes(path, suffixes, coding="UTF-8")
|
3
3
|
@items ||= []
|
4
4
|
Dir.glob("#{path}/**/*.{#{suffixes}}").each do |file|
|
5
|
-
title = file.split('/').last
|
5
|
+
title = file.split('/').last.force_encoding(coding)
|
6
6
|
puts file
|
7
7
|
|
8
8
|
puts '*' * 70
|
9
|
-
codes = File.read(file)
|
9
|
+
codes = File.read(file).force_encoding(coding)
|
10
10
|
# sb的软件著作权要求不能有空行
|
11
11
|
codes = codes.squeeze("\n")
|
12
12
|
puts codes
|
@@ -17,12 +17,17 @@ class Codes21
|
|
17
17
|
@items
|
18
18
|
end
|
19
19
|
|
20
|
-
def write_result(result_file_path)
|
20
|
+
def write_result(result_file_path, coding="UTF-8")
|
21
21
|
File.open(result_file_path, 'w') do |f|
|
22
22
|
@items.each do |item|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
title = "File:" + item[:title]
|
24
|
+
code_label = "Code:"
|
25
|
+
codes = item[:codes]
|
26
|
+
|
27
|
+
content = title + "\n" + code_label + "\n" + codes + "\n"
|
28
|
+
content = content.squeeze("\n")
|
29
|
+
|
30
|
+
f.print content.encode(coding)
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
@@ -30,10 +35,10 @@ class Codes21
|
|
30
35
|
puts "codes files count: #{@items.size}"
|
31
36
|
end
|
32
37
|
|
33
|
-
def self.run(path, suffixes, result_file_path)
|
38
|
+
def self.run(path, suffixes, result_file_path, input_coding="UTF-8", output_coding="UTF-8")
|
34
39
|
codes21 = Codes21.new
|
35
|
-
codes21.get_codes(path, suffixes)
|
36
|
-
codes21.write_result(result_file_path)
|
40
|
+
codes21.get_codes(path, suffixes, input_coding)
|
41
|
+
codes21.write_result(result_file_path, output_coding)
|
37
42
|
end
|
38
43
|
|
39
44
|
end
|