unrich 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d9f976e75fff26f4b4d772ff7f689533734d8c51ddca921e61321d1c818932e
4
- data.tar.gz: 83f6188b73c662c46d7afee2b5a78c2c0488339a2d1d88fac92a30bedf7f312d
3
+ metadata.gz: 71482bedde3fd376366658a9fcdd917c4d9a3096bcbfc3dabe5ca5c5e2ca8675
4
+ data.tar.gz: 2009a3a7694564fb1b6594f9a3b6aac8a068dac406266783f5cfc97bc89ffcf8
5
5
  SHA512:
6
- metadata.gz: 3e73d02ec44022c0dd111639a0221cbc7740b32d047744ae3769bbc43771eb6947e34276bbf2608c152d6f055e254f25be0495014826ff0e5f0cbeb225a31de9
7
- data.tar.gz: 2dd8293dba9901436dcc805fc7e13e80ca691f02e112ea8b704c7c2a331a03e7b7318a0ae20ba68541b5ba6c3a70289863a8545f8d5d5aa241adf8454ea03f0a
6
+ metadata.gz: 942327de8985c4c3da35556993265f1a7f8b5934b4f99c0efc35ed62605ac6ed4db90c267ace4025b61a3b324a7930ef990c0bc0064e2c7c476b0686520dea8a
7
+ data.tar.gz: 00daf1fd11d3408cfe77c559e50b85a1efae22186b1ad6bce43367859cbb2a095b6858e4c466808254731575873b621d84007f698a43d376d64d917d6ad7992d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+
4
+ ## [0.1.2] - 2022-05-06
5
+
6
+ - Additional cleanup
7
+ - Use fallback encoding when none is found
8
+ - More specs
9
+
3
10
  ## [0.1.0] - 2022-05-06
4
11
 
5
12
  - Initial release
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Unrich
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/unrich.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  require_relative "unrich/version"
4
4
 
5
5
  module Unrich
6
+ DEFAULT_ENCODING = "Windows-1252"
7
+
6
8
  class Error < StandardError; end
7
9
 
8
10
  # Main class that parses the richt text to unrich text, read regular plain text
@@ -15,14 +17,15 @@ module Unrich
15
17
 
16
18
  def encoding
17
19
  @encoding ||= {
18
- "ansicpg1252" => "Windows-1252"
19
- }[rtf_text.match(/\A\{\\rtf1\\([a-zA-Z0-9]*)\\([a-zA-Z0-9]*)\\/)[2]]
20
+ "ansicpg1252" => "Windows-1252",
21
+ nil => nil
22
+ }[rtf_text.match(/\A\{\\rtf1\\([a-zA-Z0-9]*)\\([a-zA-Z0-9]*)\\/)&.[](2)]
20
23
  end
21
24
 
22
25
  def to_txt
23
26
  txt = rtf_text.gsub(/\\\'([a-z0-9]{2})/) { |a|
24
27
  [a.sub("\\'",
25
- '')].pack("H*").force_encoding(encoding).encode("utf-8")
28
+ '')].pack("H*").force_encoding(encoding || Unrich::DEFAULT_ENCODING).encode("utf-8")
26
29
  }
27
30
  .gsub(/\\par\s/, "\n")
28
31
  .sub('{\rtf1', "")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unrich
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - murb
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-08 00:00:00.000000000 Z
11
+ date: 2022-05-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: unrich is a pure ruby rtf2txt converter; it reads an rtf and can only
14
14
  output it as UTF-8 encoded string