tmx_importer 1.1.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bea8f8bb85029d0b336fdf89adecdcce179fc7df
4
- data.tar.gz: c005d43b81b20c87a88b15f0814f63550655240c
3
+ metadata.gz: 3257bc81284bce15ebf42b0e8505f25314473bcc
4
+ data.tar.gz: 930e6d4e5e16d72f6c46d6d29a0170a37049c460
5
5
  SHA512:
6
- metadata.gz: 464e050de392148bd8348bc7ce23f5834f9f112cad6deedf971ba1f8a8095e2f9adac1d8ff670f9031546696e54296cac5213f9ac3e8faf90691dcf0fb373c71
7
- data.tar.gz: 180830aae81b47dcff661e1b90435558226457c177ca1a10a691ccbd8d6d08f45f0e8705d1154524975dc2de607a4c6d0dc7e0829b1e7bb3aed1155291bed43e
6
+ metadata.gz: 4d3b0951312776fb1046bbbf8fb029b7d4829b9bcac0d4904909eb286d26327de136afa9c623692f0a6468e774628ede5bdd12d1399c1f4139d0a164830dfd18
7
+ data.tar.gz: 521f1f035a34c5e0c0785901c08b5720b0729ba85104bbedc6ec57676981070ed971935a4b832a8105138de628473fb8f76f0c32895f1c0c2ae13ca6d3a52afe
@@ -1,3 +1,3 @@
1
1
  module TmxImporter
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
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(File.read(@file_path)[0..100_000])[:encoding]
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(File.read(open(@file_path)), @encoding, 'UTF-8') if !@encoding.eql?('UTF-8')
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!(/(?<=encoding=").*(?=")/, 'utf-8').gsub(/&#x[0-1]?[0-9a-fA-F];/, ' ').gsub(/[\0-\x1f\x7f\u2028]/, ' ')
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
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'open-uri'
2
3
 
3
4
  describe TmxImporter do
4
5
  it 'has a version number' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmx_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin S. Dias