plain_text 0.5.1 → 0.6
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/README.en.rdoc +18 -9
- data/bin/yard2md_afterclean +7 -7
- data/lib/plain_text.rb +13 -13
- data/lib/plain_text/parse_rule.rb +3 -3
- data/lib/plain_text/part.rb +42 -42
- data/plain_text.gemspec +1 -1
- data/test/test_plain_text_part.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daeda100de65b1faf0ed6c93ba5cb698761d9ac6bd0c9e7ed896832ce04598e7
|
4
|
+
data.tar.gz: 7d2edcae09978ed8d1630e9526d4ef2611a96da0ecd8c1d859936dd266f78619
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2ffb6c2482e623dfa077c893417e64648be555c8eb8f4fc141f8a0b108839e6e041d15527d5564b2339087edc26d49eef9e40828c00233369b560f12c1c70db
|
7
|
+
data.tar.gz: 164757b808185ebff8ab4e24bbef211c1afb46634e6156cc27bd237bb301bfc3323f2b8ea988721720e0c6b3f83ec560112f1324ebf53ab8fdc314821e3f7d9a
|
data/ChangeLog
CHANGED
data/README.en.rdoc
CHANGED
@@ -30,9 +30,9 @@ such as, {PlainText.clean_text} and {PlainText.count_char}.
|
|
30
30
|
=== PlainText::Part - Core class to describe the logical structure
|
31
31
|
|
32
32
|
In the namespace of this module, it contains {PlainText::Part} class,
|
33
|
-
which is the heart to describe the logical structure of
|
33
|
+
which is the heart to describe the logical structure of a document.
|
34
34
|
It is basically a container class and indeed a sub-class of Array. It
|
35
|
-
can contain either of
|
35
|
+
can contain either of other (multiple) {PlainText::Part} or more basic
|
36
36
|
components of either of {PlainText::Part::Paragraph} and
|
37
37
|
{PlainText::Part::Boundary}, both of which are sub-classes of String.
|
38
38
|
|
@@ -64,7 +64,7 @@ An example instance looks like this:
|
|
64
64
|
(5) Boundary::General
|
65
65
|
)
|
66
66
|
|
67
|
-
where the
|
67
|
+
where the names of the subclasses (or constants) here are arbitrary, except for
|
68
68
|
{PlainText::Part::Paragraph::Empty} and
|
69
69
|
{PlainText::Part::Boundary::Empty}, which are pre-defined. Users can
|
70
70
|
define their own subclasses to help organize the logical structure at
|
@@ -73,9 +73,18 @@ their will.
|
|
73
73
|
Basically, at every layer, every {PlainText::Part} or
|
74
74
|
{PlainText::Part::Paragraph} is sandwiched by
|
75
75
|
{PlainText::Part::Boundary}, except for the very first one.
|
76
|
+
The former contains something significant on its own, whereas the
|
77
|
+
latter (Boundary) contains nothing significant on its own, except they
|
78
|
+
may indicate the type of the following (or preceding) entity, such as
|
79
|
+
a title or section.
|
76
80
|
|
77
|
-
|
78
|
-
|
81
|
+
In this library (document, classes and modules), the former and latter
|
82
|
+
are collectively referred to as Para (or Paras) and Boundary (or
|
83
|
+
Boundaries), respectively. Namely, a Para means either of
|
84
|
+
{PlainText::Part} and {PlainText::Part::Paragraph}.
|
85
|
+
|
86
|
+
By performing +Part#join+ method, one can retrieve the entire document as a
|
87
|
+
String instance any time, just like +Array#join+.
|
79
88
|
|
80
89
|
=== PlainText::ParseRule - Class to describe the rule of how to parse
|
81
90
|
|
@@ -87,13 +96,13 @@ A rule, Proc, is defined by a user and is designed to receive either
|
|
87
96
|
String (the first application only) or {PlainText::ParseRule} (Array)
|
88
97
|
and to return a fully (or partially) parsed {PlainText::ParseRule}.
|
89
98
|
In short, the rule descries how to determine from where to where a
|
90
|
-
|
91
|
-
sections and sub-sections and so on are.
|
99
|
+
Paras and Boundaries are located — for example, what and where the
|
100
|
+
sections and sub-sections are and so on are.
|
92
101
|
|
93
102
|
For example, if a rule is Regexp, it describes how to split a String;
|
94
103
|
it is applied to String in the first application, but if it is
|
95
|
-
applied (and maybe registered as such) at the second or later
|
96
|
-
it is applied to each
|
104
|
+
applied (and maybe registered as such) at the second or later stages,
|
105
|
+
it is applied to each Para separately to split them further.
|
97
106
|
|
98
107
|
{PlainText::ParseRule#apply} and {PlainText::Part.parse} are the
|
99
108
|
standard methods to apply the rules to an object (either String or
|
data/bin/yard2md_afterclean
CHANGED
@@ -124,7 +124,7 @@ end
|
|
124
124
|
# @return [Integer]
|
125
125
|
def min_indent(str, lb=$/)
|
126
126
|
return 0 if str.empty?
|
127
|
-
lines = PlainText::Part.parse(str).
|
127
|
+
lines = PlainText::Part.parse(str).paras.join("\n").split("\n")
|
128
128
|
lines.map{|ec| indent_line(ec)}.min
|
129
129
|
end
|
130
130
|
|
@@ -149,7 +149,7 @@ end
|
|
149
149
|
# @return [Integer]
|
150
150
|
def last_indent(str, indent_prev=0, lb=$/)
|
151
151
|
return indent_prev if !str || str.empty?
|
152
|
-
lines = PlainText::Part.parse(str).
|
152
|
+
lines = PlainText::Part.parse(str).paras.join("\n").split("\n")
|
153
153
|
# Note: numsps = 2 # "2." takes up 2 spaces, whereas "12." takes 3.
|
154
154
|
lines.each do |ec|
|
155
155
|
cind = indent_line(ec)
|
@@ -184,10 +184,10 @@ opts = handle_argv()
|
|
184
184
|
|
185
185
|
strin = ARGF.read
|
186
186
|
## split to paras, fixing inline code blocks
|
187
|
-
|
187
|
+
mdpara = PlainText::Part.parse(strin)
|
188
188
|
|
189
|
-
indent_prev = last_indent(
|
190
|
-
|
189
|
+
indent_prev = last_indent(mdpara[0])
|
190
|
+
mdpara.merge_para_if{ |pbp, _, _|
|
191
191
|
prev_cb = md_code_block?(pbp[0], indent_prev)
|
192
192
|
next_cb = md_code_block?(pbp[2], indent_prev)
|
193
193
|
next true if prev_cb && next_cb
|
@@ -196,7 +196,7 @@ mdpart.merge_para_if{ |pbp, _, _|
|
|
196
196
|
}
|
197
197
|
|
198
198
|
indent_next = 0
|
199
|
-
|
199
|
+
mdpara = mdpara.map_para{|ec|
|
200
200
|
indent_prev = indent_next
|
201
201
|
indent_next = last_indent(ec, indent_prev)
|
202
202
|
next fix_string_based(ec) if !md_code_block?(ec, indent_prev)
|
@@ -205,7 +205,7 @@ mdpart = mdpart.map_part{|ec|
|
|
205
205
|
"%s```%s\n%s\n%s```"%[inde, opts[:lang], st, inde, opts[:lang]]
|
206
206
|
}
|
207
207
|
|
208
|
-
puts
|
208
|
+
puts mdpara.join('')
|
209
209
|
|
210
210
|
exit
|
211
211
|
|
data/lib/plain_text.rb
CHANGED
@@ -336,9 +336,9 @@ module PlainText
|
|
336
336
|
# Linebreaks and spaces
|
337
337
|
case lbs_style
|
338
338
|
when :truncate, :t
|
339
|
-
prt.
|
339
|
+
prt.paras.each{|ec| ec.gsub!(/\n{2,}/m, "\n")}
|
340
340
|
when :delete, :d
|
341
|
-
prt.
|
341
|
+
prt.paras.each{|ec| ec.gsub!(/\n/m, "")}
|
342
342
|
when :none, :n
|
343
343
|
# Does nothing
|
344
344
|
else
|
@@ -350,13 +350,13 @@ module PlainText
|
|
350
350
|
|
351
351
|
# Linebreaks become spaces
|
352
352
|
if lb_is_space
|
353
|
-
prt.
|
353
|
+
prt.paras.each{|ec| ec.gsub!(/\n/m, " ")}
|
354
354
|
clean_text_sps!(prt, sps_style: sps_style, is_debug: is_debug) if sps_style == :truncate
|
355
355
|
end
|
356
356
|
|
357
357
|
# Ignore spaces between, before, and after Asian characters.
|
358
358
|
if delete_asian_space
|
359
|
-
prt.
|
359
|
+
prt.paras.each do |ea_p|
|
360
360
|
PlainText.extend_this(ea_p)
|
361
361
|
ea_p.delete_spaces_bw_cjk_european! # Destructive change in prt.
|
362
362
|
end
|
@@ -380,9 +380,9 @@ module PlainText
|
|
380
380
|
# Head of each line
|
381
381
|
case linehead_style
|
382
382
|
when :truncate, :t
|
383
|
-
prt.
|
383
|
+
prt.paras.each{|ec| ec.gsub!(/^[[:blank:]]+/, " ")}
|
384
384
|
when :delete, :d
|
385
|
-
prt.
|
385
|
+
prt.paras.each{|ec| ec.gsub!(/^[[:blank:]]+/, "")}
|
386
386
|
when :none, :n
|
387
387
|
# Do nothing
|
388
388
|
else
|
@@ -392,13 +392,13 @@ module PlainText
|
|
392
392
|
# Tail of each line
|
393
393
|
case linetail_style
|
394
394
|
when :truncate, :t
|
395
|
-
prt.
|
395
|
+
prt.paras.each{|ec| ec.gsub!(/[[:blank:]]+$/, " ")}
|
396
396
|
when :delete, :d
|
397
|
-
prt.
|
397
|
+
prt.paras.each{|ec| ec.gsub!(/[[:blank:]]+$/, "")}
|
398
398
|
when :markdown, :m
|
399
399
|
# Two spaces are preserved
|
400
|
-
prt.
|
401
|
-
prt.
|
400
|
+
prt.paras.each{|ec| ec.gsub!(/(?:^|(?<![[:blank:]]))[[:blank:]]$/, "")} # A single space is deleted.
|
401
|
+
prt.paras.each{|ec| ec.gsub!(/[[:blank:]]+ $/, " ")} # 3 or more spaces are truncated into 2 spaces, only IF the last two spaces are the ASCII spaces.
|
402
402
|
when :none, :n
|
403
403
|
# Do nothing
|
404
404
|
else
|
@@ -499,10 +499,10 @@ module PlainText
|
|
499
499
|
is_debug: false
|
500
500
|
)
|
501
501
|
|
502
|
-
prt.
|
502
|
+
prt.paras.each do |e_pa|
|
503
503
|
# Each line treated as a Paragraph, and [[:space:]]+ between them as a Boundary.
|
504
504
|
# Then, to work on anything within a line except for line-head/tail is easy.
|
505
|
-
prt_para = Part.parse(e_pa, rule: ParseRule::RuleEachLineStrip).
|
505
|
+
prt_para = Part.parse(e_pa, rule: ParseRule::RuleEachLineStrip).map_para { |e_li|
|
506
506
|
case sps_style
|
507
507
|
when :truncate, :t
|
508
508
|
e_li.gsub(/[[:blank:]]{2,}/m, " ")
|
@@ -513,7 +513,7 @@ module PlainText
|
|
513
513
|
else
|
514
514
|
raise ArgumentError
|
515
515
|
end
|
516
|
-
} #
|
516
|
+
} # map_para
|
517
517
|
e_pa.replace prt_para.join
|
518
518
|
end
|
519
519
|
end
|
@@ -12,8 +12,8 @@ module PlainText
|
|
12
12
|
# which returns an Array (referred to as +ary+ hereafter).
|
13
13
|
#
|
14
14
|
# The returned array +ary+ may contain Strings at the basic level. In that case,
|
15
|
-
# any
|
16
|
-
# semantically {PlainText::Part::Paragraph} or {PlainText::Part}, which can be further parsed
|
15
|
+
# any odd-index elements are semantically Boundaries ({PlainText::Part::Boundary}) and any even-index elements are
|
16
|
+
# semantically Paras ({PlainText::Part::Paragraph} or {PlainText::Part}), which can be further parsed
|
17
17
|
# in the later processing.
|
18
18
|
#
|
19
19
|
# Alternatively, the returned array +ary+ may contain
|
@@ -78,7 +78,7 @@ module PlainText
|
|
78
78
|
#
|
79
79
|
# Then,
|
80
80
|
#
|
81
|
-
# pt1.
|
81
|
+
# pt1.paras[0].paras[1] # => Paragraph::Title("Breaking!")
|
82
82
|
# pt1.boundaries[1] # => Boundary("\n======\n")
|
83
83
|
#
|
84
84
|
# @todo
|
data/lib/plain_text/part.rb
CHANGED
@@ -42,7 +42,7 @@ module PlainText
|
|
42
42
|
# (5) Boundary::General
|
43
43
|
# )
|
44
44
|
#
|
45
|
-
# A Section (Part) always has an even number of elements: pairs of ({Part}|{Paragraph}) and {Boundary} in this order.
|
45
|
+
# A Section (Part) always has an even number of elements: pairs of a Para ({Part}|{Paragraph}) and {Boundary} in this order.
|
46
46
|
#
|
47
47
|
# Note some standard destructive Array operations, most notably +#delete+, +#delete_if+, +#reject!+,
|
48
48
|
# +#select!+, +#filter!+, +#keep_if+, +#flatten!+, +#uniq!+ may alter the content in a way
|
@@ -83,7 +83,7 @@ module PlainText
|
|
83
83
|
}
|
84
84
|
private_constant :ERR_MSGS
|
85
85
|
|
86
|
-
# @param arin [Array] of [Paragraph1, Boundary1, Para2, Bd2, ...] or
|
86
|
+
# @param arin [Array] of [Paragraph1, Boundary1, Para2, Bd2, ...] or just Paragraphs if boundaries is given as the second arguments
|
87
87
|
# @param boundaries [Array] of Boundary
|
88
88
|
# @option recursive: [Boolean] if true (Default), normalize recursively.
|
89
89
|
# @option compact: [Boolean] if true (Default), pairs of nil paragraph and boundary are removed. Otherwise, nil is converted to an empty string.
|
@@ -122,10 +122,10 @@ module PlainText
|
|
122
122
|
# Unique instance methods (not existing in Array)
|
123
123
|
##########
|
124
124
|
|
125
|
-
# Returns an array of
|
125
|
+
# Returns an array of boundaries (odd-number-index elements), consisting of Boundaries
|
126
126
|
#
|
127
127
|
# @return [Array<Boundary>]
|
128
|
-
# @see #
|
128
|
+
# @see #paras
|
129
129
|
def boundaries
|
130
130
|
select.with_index { |_, i| i.odd? } rescue select.each_with_index { |_, i| i.odd? } # Rescue for Ruby 2.1 or earlier
|
131
131
|
end
|
@@ -167,20 +167,20 @@ module PlainText
|
|
167
167
|
map_boundary_core(map: false, with_index: true, **kwd, &bl)
|
168
168
|
end
|
169
169
|
|
170
|
-
# each method for
|
170
|
+
# each method for Paras only, providing also the index (always an even number) to the block.
|
171
171
|
#
|
172
|
-
# For just looping over the elements of {#
|
172
|
+
# For just looping over the elements of {#paras}, do simply
|
173
173
|
#
|
174
|
-
#
|
174
|
+
# paras.each do |ec|
|
175
175
|
# end
|
176
176
|
#
|
177
177
|
# The indices provided in this method are for the main Array,
|
178
|
-
# and hence different from {#
|
178
|
+
# and hence different from {#paras}.each_with_index
|
179
179
|
#
|
180
|
-
# @param (see #
|
180
|
+
# @param (see #map_para_with_index)
|
181
181
|
# @return as self
|
182
|
-
def
|
183
|
-
|
182
|
+
def each_para_with_index(**kwd, &bl)
|
183
|
+
map_para_core(map: false, with_index: false, **kwd, &bl)
|
184
184
|
end
|
185
185
|
|
186
186
|
# The first significant (=non-empty) element.
|
@@ -210,7 +210,7 @@ module PlainText
|
|
210
210
|
#
|
211
211
|
# @param i [Integer] index for the array of self
|
212
212
|
# @option skip_check: [Boolean] if true (Default: false), skip conversion of the negative index to positive.
|
213
|
-
# @see #
|
213
|
+
# @see #paras
|
214
214
|
def index_para?(i, skip_check: false)
|
215
215
|
skip_check ? i.even? : positive_array_index_checked(i, self).even?
|
216
216
|
end
|
@@ -261,9 +261,9 @@ module PlainText
|
|
261
261
|
map_boundary_core(with_index: true, **kwd, &bl)
|
262
262
|
end
|
263
263
|
|
264
|
-
# map method for
|
264
|
+
# map method for Paras only, returning a copied self.
|
265
265
|
#
|
266
|
-
# If recursive is true (Default), any
|
266
|
+
# If recursive is true (Default), any Paras in the descendant Parts are also handled.
|
267
267
|
#
|
268
268
|
# If a Paragraph is set nil or empty, along with the following Boundary,
|
269
269
|
# the pair is removed from the returned instance in Default (:compact and :compacter options
|
@@ -272,30 +272,30 @@ module PlainText
|
|
272
272
|
# @option recursive: [Boolean] if true (Default), map is performed recursively.
|
273
273
|
# @return as self
|
274
274
|
# @see #initialize for the other options (:compact and :compacter)
|
275
|
-
def
|
276
|
-
|
275
|
+
def map_para(**kwd, &bl)
|
276
|
+
map_para_core(with_index: false, **kwd, &bl)
|
277
277
|
end
|
278
278
|
|
279
|
-
# map method for
|
279
|
+
# map method for paras only, providing also the index (always an even number) to the block, returning a copied self.
|
280
280
|
#
|
281
|
-
# @param (see #
|
281
|
+
# @param (see #map_para)
|
282
282
|
# @return as self
|
283
|
-
def
|
284
|
-
|
283
|
+
def map_para_with_index(**kwd, &bl)
|
284
|
+
map_para_core(with_index: false, **kwd, &bl)
|
285
285
|
end
|
286
286
|
|
287
|
-
# merge
|
287
|
+
# merge Paras if they satisfy the conditions.
|
288
288
|
#
|
289
|
-
# A group of two
|
289
|
+
# A group of two Paras and the Boundaries in between and before and after
|
290
290
|
# is passed to the block consecutively.
|
291
291
|
#
|
292
292
|
# @yield [ary, b1, b2, i] Returns true if the two paragraphs should be merged.
|
293
293
|
# @yieldparam [Array] ary of [Para1st, BoundaryBetween, Para2nd]
|
294
|
-
# @yieldparam [Boundary] b1 Boundary-String before the first
|
295
|
-
# @yieldparam [Boundary] b2 Boundary-String after the second
|
294
|
+
# @yieldparam [Boundary] b1 Boundary-String before the first Para (nil for the first one)
|
295
|
+
# @yieldparam [Boundary] b2 Boundary-String after the second Para
|
296
296
|
# @yieldparam [Integer] i Index of the first Para
|
297
297
|
# @yieldreturn [Boolean, Symbol] True if they should be merged. :abort if cancel it.
|
298
|
-
# @return [self, false] false if no pairs of
|
298
|
+
# @return [self, false] false if no pairs of Paras are merged, else self.
|
299
299
|
def merge_para_if()
|
300
300
|
arind2del = [] # Indices to delete (both paras and boundaries)
|
301
301
|
each_index do |ei|
|
@@ -328,7 +328,7 @@ module PlainText
|
|
328
328
|
# @overload set(range)
|
329
329
|
# With a range of the indices to merge. Unless use_para_index is true, this means the main Array index. See the first overload set about it.
|
330
330
|
# @param range [Range] describe value param
|
331
|
-
# @param use_para_index: [Boolean] If false (Default), the indices are for the main indices (alternative between
|
331
|
+
# @param use_para_index: [Boolean] If false (Default), the indices are for the main indices (alternative between Paras and Boundaries, starting from Para). If true, the indices are as obtained with {#paras}, namely the array containing only Paras.
|
332
332
|
# @return [self, nil] nil if nothing is merged (because of wrong indices).
|
333
333
|
def merge_para!(*rest, use_para_index: false)
|
334
334
|
$myd = true
|
@@ -449,11 +449,11 @@ $myd = false
|
|
449
449
|
end
|
450
450
|
|
451
451
|
|
452
|
-
# Returns an array of
|
452
|
+
# Returns an array of Paras (even-number-index elements), consisting of Part and/or Paragraph
|
453
453
|
#
|
454
454
|
# @return [Array<Part, Paragraph>]
|
455
455
|
# @see #boundaries
|
456
|
-
def
|
456
|
+
def paras
|
457
457
|
select.with_index { |_, i| i.even? } rescue select.each_with_index { |_, i| i.even? } # Rescue for Ruby 2.1 or earlier
|
458
458
|
# ret.freeze
|
459
459
|
end
|
@@ -581,7 +581,7 @@ $myd = false
|
|
581
581
|
# @param other [Object]
|
582
582
|
def ==(other)
|
583
583
|
return false if !other.class.method_defined?(:to_ary)
|
584
|
-
%i(
|
584
|
+
%i(paras boundaries).each do |ea_m| # %i(...) defined in Ruby 2.0 and later
|
585
585
|
return false if !other.class.method_defined?(ea_m) || (self.public_send(ea_m) != other.public_send(ea_m)) # public_send() defined in Ruby 2.0 (1.9?) and later
|
586
586
|
end
|
587
587
|
super
|
@@ -603,20 +603,20 @@ $myd = false
|
|
603
603
|
# @return as self
|
604
604
|
def +(other)
|
605
605
|
# ## The following is strict, but a bit redundant.
|
606
|
-
# #
|
607
|
-
# # %i(to_ary
|
608
|
-
# #
|
606
|
+
# # is_para = true # Whether "other" is a Part class instance.
|
607
|
+
# # %i(to_ary paras boundaries).each do |ea_m| # %i(...) defined in Ruby 2.0 and later
|
608
|
+
# # is_para &&= other.class.method_defined?(ea_m)
|
609
609
|
# # end
|
610
610
|
|
611
611
|
# begin
|
612
612
|
# other_even_odd =
|
613
|
-
# ([other.
|
613
|
+
# ([other.paras, other.boundaries] rescue even_odd_arrays(self, size_even: true, filler: ""))
|
614
614
|
# rescue NoMethodError
|
615
615
|
# raise TypeError, sprintf("no implicit conversion of %s into %s", other.class.name, self.class.name)
|
616
616
|
# end
|
617
617
|
|
618
618
|
# # eg., if self is PlainText::Part::Section, the returned object is the same.
|
619
|
-
# ret = self.class.new(self.
|
619
|
+
# ret = self.class.new(self.paras+other_even_odd[0], self.boundaries+other_even_odd[1])
|
620
620
|
ret = self.class.new super
|
621
621
|
ret.normalize!
|
622
622
|
end
|
@@ -733,7 +733,7 @@ $myd = false
|
|
733
733
|
# The result may not be in an even number anymore. Correct it.
|
734
734
|
Boundary.insert_original_b4_part(size, "") if size.odd?
|
735
735
|
|
736
|
-
# Original method may fill some
|
736
|
+
# Original method may fill some elements of the array with String or even nil.
|
737
737
|
normalize!
|
738
738
|
ret
|
739
739
|
end
|
@@ -892,7 +892,7 @@ $myd = false
|
|
892
892
|
# @return [Integer, nil] nil if a too large index is specified.
|
893
893
|
def get_valid_ipos_for_boundary(index)
|
894
894
|
i_pos = positive_array_index_checked(index, self)
|
895
|
-
raise ArgumentError, "Index #{index} specified was for
|
895
|
+
raise ArgumentError, "Index #{index} specified was for Para, which should be for Boundary." if index_para?(i_pos, skip_check: true)
|
896
896
|
(i_pos > size - 1) ? nil : i_pos
|
897
897
|
end
|
898
898
|
private :get_valid_ipos_for_boundary
|
@@ -920,16 +920,16 @@ $myd = false
|
|
920
920
|
end
|
921
921
|
private :map_boundary_core
|
922
922
|
|
923
|
-
# Core routine for {#
|
923
|
+
# Core routine for {#map_para}
|
924
924
|
#
|
925
925
|
# @option map: [Boolean] if true (Default), map is performed. Else just each.
|
926
926
|
# @option with_index: [Boolean] if true (Default: false), yield with also index
|
927
927
|
# @option recursive: [Boolean] if true (Default), map is performed recursively.
|
928
928
|
# @return as self
|
929
929
|
# @see #initialize for the other options (:compact and :compacter)
|
930
|
-
def
|
930
|
+
def map_para_core(map: true, with_index: false, recursive: true, **kwd, &bl)
|
931
931
|
ind = -1
|
932
|
-
|
932
|
+
new_paras = paras.map{ |ec|
|
933
933
|
ind += 1
|
934
934
|
if recursive && ec.class.method_defined?(__method__)
|
935
935
|
ec.public_send(__method__, recursive: true, **kwd, &bl)
|
@@ -937,9 +937,9 @@ $myd = false
|
|
937
937
|
with_index ? yield(ec, ind) : yield(ec)
|
938
938
|
end
|
939
939
|
}
|
940
|
-
self.class.new
|
940
|
+
self.class.new new_paras, boundaries, recursive: recursive, **kwd if map
|
941
941
|
end
|
942
|
-
private :
|
942
|
+
private :map_para_core
|
943
943
|
|
944
944
|
# Core routine for {#normalize!} and {#normalize}
|
945
945
|
#
|
@@ -1051,7 +1051,7 @@ class Array
|
|
1051
1051
|
# @param other [Object]
|
1052
1052
|
def ==(other)
|
1053
1053
|
return false if !other.class.method_defined?(:to_ary)
|
1054
|
-
%i(
|
1054
|
+
%i(paras boundaries).each do |ea_m| # %i(...) defined in Ruby 2.0 and later
|
1055
1055
|
return equal_original_b4_part?(other) if !other.class.method_defined?(ea_m)
|
1056
1056
|
return false if !self.class.method_defined?(ea_m) || (self.public_send(ea_m) != other.public_send(ea_m)) # public_send() defined in Ruby 2.0 (1.9?) and later
|
1057
1057
|
end
|
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.
|
8
|
+
s.version = "0.6".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|
|
@@ -50,7 +50,7 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
50
50
|
# p pt1.to_a.class
|
51
51
|
assert_equal a1[0], pt1[0]
|
52
52
|
assert_equal a1[1], pt1[1]
|
53
|
-
assert_equal ap1, pt1.
|
53
|
+
assert_equal ap1, pt1.paras
|
54
54
|
assert_equal ab1, pt1.boundaries
|
55
55
|
assert_equal a1, pt1.to_a
|
56
56
|
assert_operator a1, '!=', pt1
|
@@ -59,7 +59,7 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
59
59
|
pt2 = Pt.new(a2)
|
60
60
|
assert_equal a2[0], pt2[0]
|
61
61
|
assert_equal a2[2], pt2[2]
|
62
|
-
assert_equal ap2, pt2.
|
62
|
+
assert_equal ap2, pt2.paras
|
63
63
|
assert_equal ab2, pt2.boundaries
|
64
64
|
assert_equal a2+[""], pt2.to_a # An empty String is appended.
|
65
65
|
assert_operator a2, '!=', pt2
|
@@ -196,7 +196,7 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
196
196
|
|
197
197
|
pt2 = pt1[0, 4]
|
198
198
|
assert_equal pt1.class, pt2.class
|
199
|
-
assert_equal pt1.
|
199
|
+
assert_equal pt1.paras[0, 2], pt2.paras
|
200
200
|
assert_equal pt1.boundaries[0, 2], pt2.boundaries
|
201
201
|
|
202
202
|
# negative or too-big out-of-bound begin
|
@@ -337,7 +337,7 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
337
337
|
# 0 1 2 3 4 5 6 7 8 9
|
338
338
|
pt1 = Pt.parse s1
|
339
339
|
assert_equal 10, pt1.size
|
340
|
-
assert_equal 5, pt1.
|
340
|
+
assert_equal 5, pt1.paras.size
|
341
341
|
assert_equal "b\n\n", pt1[2..3].join
|
342
342
|
|
343
343
|
pt2 = pt1.dup
|
@@ -417,8 +417,8 @@ class TestUnitPlainTextPart < MiniTest::Test
|
|
417
417
|
s1 = "a\n\n\nb\n\n\nc\n\n"
|
418
418
|
pt1 = Pt.parse s1
|
419
419
|
assert_equal 6, pt1.size
|
420
|
-
assert_equal 3, pt1.
|
421
|
-
assert_equal %w(a b c), pt1.
|
420
|
+
assert_equal 3, pt1.paras.size
|
421
|
+
assert_equal %w(a b c), pt1.paras
|
422
422
|
assert_equal Pt::Paragraph, pt1[0].class
|
423
423
|
assert_equal Pt::Boundary, pt1[1].class
|
424
424
|
assert_equal s1, pt1.join
|