plain_text 0.7 → 0.7.1
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 +5 -0
- data/lib/plain_text.rb +1 -1
- data/plain_text.gemspec +3 -3
- data/test/test_plain_text.rb +12 -2
- data/test/test_plain_text_part.rb +40 -26
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 45fae90fbac6ba53a5f7c21d6a21b3f858d3db734d770eec82fdbb9838755b11
|
|
4
|
+
data.tar.gz: 2817d7be2e4e7a3029d00922177c881ae4cdad2c940bb764f8f49cd6c1b08e00
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5443ef391054d08a06f3cef5a67316b0f13ddbf2f60f7689eb51f027aa73804e09418d0e021446cc32f90111047f36a862278a62b92017000055658756fb4759
|
|
7
|
+
data.tar.gz: 0b158d573ba75b957a0c063aace1bad6c378a23e3e8cd97afe2af6cbd71e79bf26cdd32cce748c0fefd24f61cd6d9053380178889c3c30673219d1bcb13b8809
|
data/ChangeLog
CHANGED
data/lib/plain_text.rb
CHANGED
|
@@ -139,7 +139,7 @@ module PlainText
|
|
|
139
139
|
# @param delete_asian_space [Boolean] Any spaces between, before, after Asian characters (but punctuation) are deleted, if true (Default).
|
|
140
140
|
# @param linehead_style [Symbol] One of +(:truncate|:delete|:none)+ (Def: :none). Determine how to handle consecutive white spaces at the beggining of each line.
|
|
141
141
|
# @param linetail_style [Symbol] One of +(:truncate|:delete|:markdown|:none)+ (Def: :delete). Determine how to handle consecutive white spaces at the end of each line. If +:markdown, 1 space is always deleted, and two or more spaces are truncated into two ASCII whitespaces *if* the last two spaces are ASCII whitespaces, or else untouched.
|
|
142
|
-
# @param firstlbs_style [Symbol, String] One of +(:truncate|:delete|:none)+ or String (Def: :
|
|
142
|
+
# @param firstlbs_style [Symbol, String] One of +(:truncate|:delete|:none)+ or String (Def: :delete). If +:truncate+, any linebreaks at the very beginning of self (and whitespaces in between), if exist, are truncated to a single linebreak. If String, they are, even if not exists, replaced with the specified String (such as a linebreak). If +:delete+, they are deleted. Note This option has nothing to do with the whitespaces at the beginning of the first significant line (hence the name of the option). Note if a (random) Part is given, this option only considers the first significant element of it.
|
|
143
143
|
# @param lastsps_style [Symbol, String] One of +(:truncate|:delete|:none|:linebreak)+ or String (Def: :truncate). If +:truncate+, any of linebreaks *AND* white spaces at the tail of self, if exist, are truncated to a single linebreak. If +:delete+, they are deleted. If String, they are, even if not exists, replaced with the specified String (such as a linebreak, in which case +lb_out+ is used as String, i.e., it guarantees only 1 linebreak to exist at the end of the String). Note if a (random) Part is given, this option only considers the last significant element of it.
|
|
144
144
|
# @param lb [String] Linebreak character like +\n+ etc (Default: $/). If this is one of the standard line-breaks, irregular line-breaks (for example, existence of CR when only LF should be there) are corrected.
|
|
145
145
|
# @param lb_out [String] Linebreak used for output (Default: +lb+)
|
data/plain_text.gemspec
CHANGED
|
@@ -5,7 +5,7 @@ require 'date'
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{plain_text}.sub(/.*/){|c| (c == File.basename(Dir.pwd)) ? c : raise("ERROR: s.name=(#{c}) in gemspec seems wrong!")}
|
|
8
|
-
s.version = "0.7".sub(/.*/){|c| fs = Dir.glob('changelog{,.*}', File::FNM_CASEFOLD); raise('More than one ChangeLog exist!') if fs.size > 1; warn("WARNING: Version(s.version=#{c}) already exists in #{fs[0]} - ok?") if fs.size == 1 && !IO.readlines(fs[0]).grep(/^\(Version: #{Regexp.quote c}\)$/).empty? ; c } # n.b., In macOS, changelog and ChangeLog are identical in default.
|
|
8
|
+
s.version = "0.7.1".sub(/.*/){|c| fs = Dir.glob('changelog{,.*}', File::FNM_CASEFOLD); raise('More than one ChangeLog exist!') if fs.size > 1; warn("WARNING: Version(s.version=#{c}) already exists in #{fs[0]} - ok?") if fs.size == 1 && !IO.readlines(fs[0]).grep(/^\(Version: #{Regexp.quote c}\)$/).empty? ; c } # n.b., In macOS, changelog and ChangeLog are identical in default.
|
|
9
9
|
# s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
10
10
|
s.bindir = 'bin'
|
|
11
11
|
%w(countchar textclean head.rb tail.rb yard2md_afterclean).each do |f|
|
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
|
13
13
|
File.executable?(path) ? s.executables << f : raise("ERROR: Executable (#{path}) is not executable!")
|
|
14
14
|
end
|
|
15
15
|
s.authors = ["Masa Sakano"]
|
|
16
|
-
s.date = %q{2022-
|
|
16
|
+
s.date = %q{2022-09-09}.sub(/.*/){|c| (Date.parse(c) == Date.today) ? c : raise("ERROR: s.date=(#{c}) is not today!")}
|
|
17
17
|
s.summary = %q{Module to handle Plain-Text}
|
|
18
18
|
s.description = %q{This module provides utility functions and methods to handle plain text, classes Part/Paragraph/Boundary to represent the logical structure of a document and ParseRule to describe the rules to parse plain text to produce a Part-type Ruby instance. A few handy Ruby executable scripts to make use of them are included.}
|
|
19
19
|
# s.email = %q{abc@example.com}
|
|
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
|
|
|
41
41
|
s.rdoc_options = ["--charset=UTF-8"]
|
|
42
42
|
|
|
43
43
|
# s.require_paths = ["lib"] # Default "lib"
|
|
44
|
-
s.required_ruby_version = '>= 2.0'
|
|
44
|
+
s.required_ruby_version = '>= 2.0', '< 3.2'
|
|
45
45
|
s.test_files = Dir['test/**/*.rb']
|
|
46
46
|
s.test_files.reject! { |fn| File.symlink? fn }
|
|
47
47
|
# s.requirements << 'libmagick, v6.0' # Simply, info to users.
|
data/test/test_plain_text.rb
CHANGED
|
@@ -301,12 +301,22 @@ class TestUnitPlainText < MiniTest::Test
|
|
|
301
301
|
assert_equal "", PT.tail_inverse("", 3)
|
|
302
302
|
|
|
303
303
|
# Child class of String
|
|
304
|
+
# NOTE: In Ruby 3, a subclass of String is not respected in the methods of String:
|
|
305
|
+
# @see https://rubyreferences.github.io/rubychanges/3.0.html#string-always-returning-string
|
|
306
|
+
# NOTE: In Ruby 3, "".class.name is frozen?==true
|
|
304
307
|
chs = ChString.new ""
|
|
305
|
-
|
|
308
|
+
require 'rubygems' if !defined? Gem # for Ruby 1
|
|
309
|
+
is_ver_2 = (Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3'))
|
|
310
|
+
nam = (is_ver_2 ? chs.class : String).name
|
|
311
|
+
|
|
306
312
|
assert_equal "", chs
|
|
307
313
|
assert_equal chs, PT.tail(chs)
|
|
308
314
|
assert_equal nam, PT.tail(chs).class.name, nam+" <=> \n"+PT.tail(chs).class.name.inspect
|
|
309
|
-
|
|
315
|
+
if is_ver_2
|
|
316
|
+
assert_equal nam, PT.tail(chs.class.name)
|
|
317
|
+
else
|
|
318
|
+
assert_raises(FrozenError){ PT.tail(chs.class.name) }
|
|
319
|
+
end
|
|
310
320
|
assert_equal nam, PT.tail(chs, -100).class.name
|
|
311
321
|
end
|
|
312
322
|
|
|
@@ -18,6 +18,12 @@ gem "minitest"
|
|
|
18
18
|
require 'minitest/autorun'
|
|
19
19
|
# MiniTest::Unit.autorun
|
|
20
20
|
|
|
21
|
+
# NOTE: In Ruby 3, a subclass of Array is not respected in the methods of Array:
|
|
22
|
+
# @see https://rubyreferences.github.io/rubychanges/3.0.html#array-always-returning-array
|
|
23
|
+
# NOTE: In Ruby 3, "".class.name is frozen?==true
|
|
24
|
+
require 'rubygems' if !defined? Gem # for Ruby 1
|
|
25
|
+
IS_VER_2 = (Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3'))
|
|
26
|
+
|
|
21
27
|
class TestUnitPlainTextPart < MiniTest::Test
|
|
22
28
|
T = true
|
|
23
29
|
F = false
|
|
@@ -143,7 +149,7 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
|
143
149
|
assert_equal a1+["d", ""], pt3.to_a
|
|
144
150
|
assert_equal pt1.class, pt3.class
|
|
145
151
|
assert_equal Pt.new(a3), pt3 # Boundary("") is appended.
|
|
146
|
-
assert_equal Pt::Boundary, pt3.to_a[-1].class
|
|
152
|
+
assert_equal Pt::Boundary, pt3.to_a[-1].class if IS_VER_2 # Not in Ruby 3 (see note at the top)
|
|
147
153
|
assert_equal pt3, pt1 + ["d", ""]
|
|
148
154
|
|
|
149
155
|
assert_equal a3.class, ([]+pt3).class # The latter, too, is an Array (NOT PlainText::Part)
|
|
@@ -154,6 +160,9 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
|
154
160
|
end
|
|
155
161
|
|
|
156
162
|
# Tests of [prm], [prm1, prm2], [prm1..prm2] and "equal" operator
|
|
163
|
+
# NOTE: In Ruby 3, a subclass of Array is not respected in the methods of Array:
|
|
164
|
+
# @see https://rubyreferences.github.io/rubychanges/3.0.html#array-always-returning-array
|
|
165
|
+
# NOTE: In Ruby 3, "".class.name is frozen?==true
|
|
157
166
|
def test_bracket01
|
|
158
167
|
a1 = ["a", "\n\n\n", "b", "\n\n\n", "c", "\n\n"]
|
|
159
168
|
pt1 = Pt.new(a1)
|
|
@@ -167,17 +176,18 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
|
167
176
|
assert_nil pt1[-99]
|
|
168
177
|
assert_nil pt1[98]
|
|
169
178
|
|
|
170
|
-
assert_equal pt1.class, pt1[0, 6].class
|
|
179
|
+
assert_equal pt1.class, pt1[0, 6].class if IS_VER_2 # Not in Ruby 3 (see note at the top)
|
|
171
180
|
assert_equal a1, pt1[0, 6].to_a
|
|
172
181
|
assert_equal a1[0, 6], pt1[0, 6].to_a
|
|
173
|
-
|
|
174
|
-
assert_operator
|
|
182
|
+
oper = (IS_VER_2 ? :!= : :==) # Because PlainText::Part#== is redefined and pt1 is Part in Ruby 2, the following is unequal, whereas pt1 is Array in Ruby 3!
|
|
183
|
+
assert_operator pt1[0, 6], oper, a1
|
|
184
|
+
assert_operator a1, oper, pt1[0, 6]
|
|
175
185
|
|
|
176
186
|
assert_equal a1[0, 2], pt1[0, 2].to_a
|
|
177
187
|
assert_equal a1, pt1[0, 98].to_a
|
|
178
188
|
assert_equal a1[0, 99], pt1[0, 98].to_a
|
|
179
189
|
|
|
180
|
-
assert_equal pt1.class, pt1[0..1].class
|
|
190
|
+
assert_equal pt1.class, pt1[0..1].class if IS_VER_2 # Not in Ruby 3 (see note at the top)
|
|
181
191
|
assert_equal a1[0..1], pt1[0..1].to_a
|
|
182
192
|
assert_equal a1[0, 2], pt1[0..1].to_a
|
|
183
193
|
assert_equal a1[0..5], pt1[0..5].to_a
|
|
@@ -192,12 +202,14 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
|
192
202
|
|
|
193
203
|
assert_equal pt1[0..-1], pt1[0..99]
|
|
194
204
|
assert_equal pt1[0, 6], pt1[0..-1]
|
|
195
|
-
assert_equal pt1, pt1[0..99]
|
|
205
|
+
assert_equal pt1, pt1[0..99] if IS_VER_2 # Not in Ruby 3 (see note at the top)
|
|
196
206
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
207
|
+
if IS_VER_2 # Not in Ruby 3 (see note at the top)
|
|
208
|
+
pt2 = pt1[0, 4]
|
|
209
|
+
assert_equal pt1.class, pt2.class
|
|
210
|
+
assert_equal pt1.paras[0, 2], pt2.paras
|
|
211
|
+
assert_equal pt1.boundaries[0, 2], pt2.boundaries
|
|
212
|
+
end
|
|
201
213
|
|
|
202
214
|
# negative or too-big out-of-bound begin
|
|
203
215
|
assert_nil a1[-99..2]
|
|
@@ -206,7 +218,7 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
|
206
218
|
assert_nil pt1[98..99]
|
|
207
219
|
|
|
208
220
|
# other out-of-bounds: Empty
|
|
209
|
-
assert_equal Pt.new([]), pt1[2..1]
|
|
221
|
+
assert_equal Pt.new([]), pt1[2..1] if IS_VER_2 # Not in Ruby 3 (see note at the top)
|
|
210
222
|
assert_equal a1[-2..2], pt1[-2..2].to_a
|
|
211
223
|
assert_equal a1[-2...3], pt1[-2...3].to_a
|
|
212
224
|
|
|
@@ -223,10 +235,12 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
|
223
235
|
assert_nil pt1[pt1.size]
|
|
224
236
|
assert_nil pt1[pt1.size, -2]
|
|
225
237
|
assert_raises(TypeError){ pt1[pt1.size, ?a] }
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
238
|
+
if IS_VER_2 # Not in Ruby 3 (see note at the top)
|
|
239
|
+
assert_equal Pt.new([]), pt1[pt1.size, 2]
|
|
240
|
+
assert_equal Pt.new([]), pt1[pt1.size, 98]
|
|
241
|
+
assert_equal Pt.new([]), pt1[pt1.size..99]
|
|
242
|
+
assert_equal Pt.new([]), pt1[pt1.size..1]
|
|
243
|
+
end
|
|
230
244
|
end
|
|
231
245
|
|
|
232
246
|
# Tests of slice! to delete
|
|
@@ -247,12 +261,12 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
|
247
261
|
|
|
248
262
|
assert_equal a11[4, 2], a1.slice!(4, 2)
|
|
249
263
|
ptp = pt1.slice!(4, 2)
|
|
250
|
-
assert_equal pt1.class, ptp.class # PlainText::Part
|
|
264
|
+
assert_equal pt1.class, ptp.class if IS_VER_2 # Not in Ruby 3 (see note at the top) # PlainText::Part
|
|
251
265
|
assert_equal a11[4, 2], ptp.to_a
|
|
252
|
-
assert_operator a11[4, 2], :!=, ptp # PlainText::Part != Array
|
|
266
|
+
assert_operator a11[4, 2], :!=, ptp if IS_VER_2 # PlainText::Part != Array
|
|
253
267
|
assert_equal a11[0..3], a1
|
|
254
268
|
assert_equal a11[0..3], pt1.to_a
|
|
255
|
-
assert_equal pt2[0..3], pt1
|
|
269
|
+
assert_equal pt2[0..3], pt1 if IS_VER_2 # Not in Ruby 3 (see note at the top)
|
|
256
270
|
|
|
257
271
|
# Negative size (Index, Size)
|
|
258
272
|
a1 = a11.clone
|
|
@@ -268,9 +282,9 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
|
268
282
|
pt1 = Pt.new(a11.clone)
|
|
269
283
|
assert_equal a11[4, 6], a1.slice!(4, 6)
|
|
270
284
|
ptp = pt1.slice!(4, 6)
|
|
271
|
-
assert_equal pt1.class, ptp.class # PlainText::Part
|
|
285
|
+
assert_equal pt1.class, ptp.class if IS_VER_2 # Not in Ruby 3 (see note at the top) # PlainText::Part
|
|
272
286
|
assert_equal a11[4, 2], ptp.to_a
|
|
273
|
-
assert_operator a11[4, 2], :!=, ptp # PlainText::Part != Array
|
|
287
|
+
assert_operator a11[4, 2], :!=, ptp if IS_VER_2 # Not in Ruby 3 (see note at the top) # PlainText::Part != Array
|
|
274
288
|
assert_equal a11[0..3], a1
|
|
275
289
|
|
|
276
290
|
# Range exceeding (Range)
|
|
@@ -278,10 +292,10 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
|
278
292
|
pt1 = Pt.new(a11.clone)
|
|
279
293
|
assert_equal a11[4..9], a1.slice!(4..9)
|
|
280
294
|
ptp = pt1.slice!(4..9)
|
|
281
|
-
assert_equal pt1.class, ptp.class # PlainText::Part
|
|
295
|
+
assert_equal pt1.class, ptp.class if IS_VER_2 # Not in Ruby 3 (see note at the top) # PlainText::Part
|
|
282
296
|
assert_equal a11[4..-1],ptp.to_a
|
|
283
297
|
assert_equal a11[4..9], ptp.to_a
|
|
284
|
-
assert_operator a11[4..9], :!=, ptp # PlainText::Part != Array
|
|
298
|
+
assert_operator a11[4..9], :!=, ptp if IS_VER_2 # Not in Ruby 3 (see note at the top) # PlainText::Part != Array
|
|
285
299
|
assert_equal a11[0..3], a1
|
|
286
300
|
assert_equal a11[0..3], pt1.to_a
|
|
287
301
|
|
|
@@ -301,9 +315,9 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
|
301
315
|
pt1 = Pt.new(a11.clone)
|
|
302
316
|
assert_equal a11[-6, 2], a1.slice!(-6, 2)
|
|
303
317
|
ptp = pt1.slice!(-6, 2)
|
|
304
|
-
assert_equal pt1.class, ptp.class # PlainText::Part
|
|
318
|
+
assert_equal pt1.class, ptp.class if IS_VER_2 # Not in Ruby 3 (see note at the top) # PlainText::Part
|
|
305
319
|
assert_equal a11[0..1], ptp.to_a
|
|
306
|
-
assert_operator a11[0..1], :!=, ptp # PlainText::Part != Array
|
|
320
|
+
assert_operator a11[0..1], :!=, ptp if IS_VER_2 # Not in Ruby 3 (see note at the top) # PlainText::Part != Array
|
|
307
321
|
assert_equal a11[2..-1], a1
|
|
308
322
|
assert_equal a11[2..-1], pt1.to_a
|
|
309
323
|
|
|
@@ -312,9 +326,9 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
|
312
326
|
pt1 = Pt.new(a11.clone)
|
|
313
327
|
assert_equal a11[-6..-5], a1.slice!(-6..-5)
|
|
314
328
|
ptp = pt1.slice!(-6..-5)
|
|
315
|
-
assert_equal pt1.class, ptp.class # PlainText::Part
|
|
329
|
+
assert_equal pt1.class, ptp.class if IS_VER_2 # Not in Ruby 3 (see note at the top) # PlainText::Part
|
|
316
330
|
assert_equal a11[0..1], ptp.to_a
|
|
317
|
-
assert_operator a11[0..1], :!=, ptp # PlainText::Part != Array
|
|
331
|
+
assert_operator a11[0..1], :!=, ptp if IS_VER_2 # Not in Ruby 3 (see note at the top) # PlainText::Part != Array
|
|
318
332
|
assert_equal a11[2..-1], a1
|
|
319
333
|
assert_equal a11[2..-1], pt1.to_a
|
|
320
334
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: plain_text
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 0.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Masa Sakano
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-09-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: This module provides utility functions and methods to handle plain text,
|
|
14
14
|
classes Part/Paragraph/Boundary to represent the logical structure of a document
|
|
@@ -69,6 +69,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
69
69
|
- - ">="
|
|
70
70
|
- !ruby/object:Gem::Version
|
|
71
71
|
version: '2.0'
|
|
72
|
+
- - "<"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '3.2'
|
|
72
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
76
|
requirements:
|
|
74
77
|
- - ">="
|