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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/unrich/version.rb +1 -1
- data/lib/unrich.rb +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71482bedde3fd376366658a9fcdd917c4d9a3096bcbfc3dabe5ca5c5e2ca8675
|
4
|
+
data.tar.gz: 2009a3a7694564fb1b6594f9a3b6aac8a068dac406266783f5cfc97bc89ffcf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 942327de8985c4c3da35556993265f1a7f8b5934b4f99c0efc35ed62605ac6ed4db90c267ace4025b61a3b324a7930ef990c0bc0064e2c7c476b0686520dea8a
|
7
|
+
data.tar.gz: 00daf1fd11d3408cfe77c559e50b85a1efae22186b1ad6bce43367859cbb2a095b6858e4c466808254731575873b621d84007f698a43d376d64d917d6ad7992d
|
data/CHANGELOG.md
CHANGED
data/lib/unrich/version.rb
CHANGED
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
|
-
|
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.
|
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-
|
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
|