tmx_importer 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tmx_importer/version.rb +1 -1
- data/lib/tmx_importer.rb +4 -3
- data/spec/tmx_importer_spec.rb +1 -0
- 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: 3257bc81284bce15ebf42b0e8505f25314473bcc
|
4
|
+
data.tar.gz: 930e6d4e5e16d72f6c46d6d29a0170a37049c460
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d3b0951312776fb1046bbbf8fb029b7d4829b9bcac0d4904909eb286d26327de136afa9c623692f0a6468e774628ede5bdd12d1399c1f4139d0a164830dfd18
|
7
|
+
data.tar.gz: 521f1f035a34c5e0c0785901c08b5720b0729ba85104bbedc6ec57676981070ed971935a4b832a8105138de628473fb8f76f0c32895f1c0c2ae13ca6d3a52afe
|
data/lib/tmx_importer/version.rb
CHANGED
data/lib/tmx_importer.rb
CHANGED
@@ -9,8 +9,9 @@ module TmxImporter
|
|
9
9
|
attr_reader :file_path, :encoding
|
10
10
|
def initialize(file_path:, **args)
|
11
11
|
@file_path = file_path
|
12
|
+
@content = File.read(open(@file_path)) if !args[:encoding].eql?('UTF-8')
|
12
13
|
if args[:encoding].nil?
|
13
|
-
@encoding = CharlockHolmes::EncodingDetector.detect(
|
14
|
+
@encoding = CharlockHolmes::EncodingDetector.detect(@content[0..100_000])[:encoding]
|
14
15
|
else
|
15
16
|
@encoding = args[:encoding].upcase
|
16
17
|
end
|
@@ -22,7 +23,7 @@ module TmxImporter
|
|
22
23
|
}
|
23
24
|
raise "Encoding type could not be determined. Please set an encoding of UTF-8, UTF-16LE, or UTF-16BE" if @encoding.nil?
|
24
25
|
raise "Encoding type not supported. Please choose an encoding of UTF-8, UTF-16LE, or UTF-16BE" unless @encoding.eql?('UTF-8') || @encoding.eql?('UTF-16LE') || @encoding.eql?('UTF-16BE')
|
25
|
-
@text = CharlockHolmes::Converter.convert(
|
26
|
+
@text = CharlockHolmes::Converter.convert(@content, @encoding, 'UTF-8') if !@encoding.eql?('UTF-8')
|
26
27
|
end
|
27
28
|
|
28
29
|
def stats
|
@@ -58,7 +59,7 @@ module TmxImporter
|
|
58
59
|
if encoding.eql?('UTF-8')
|
59
60
|
XML::Reader.io(open(file_path), options: XML::Parser::Options::NOERROR, encoding: XML::Encoding::UTF_8)
|
60
61
|
else
|
61
|
-
reader = @text.gsub
|
62
|
+
reader = @text.gsub(/(?<=encoding=").*(?=")/, 'utf-8').gsub(/&#x[0-1]?[0-9a-fA-F];/, ' ').gsub(/[\0-\x1f\x7f\u2028]/, ' ')
|
62
63
|
XML::Reader.string(reader, options: XML::Parser::Options::NOERROR, encoding: XML::Encoding::UTF_8)
|
63
64
|
end
|
64
65
|
end
|
data/spec/tmx_importer_spec.rb
CHANGED