string-text 0.4.0 → 0.5.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 +4 -4
- data/lib/string-text/version.rb +1 -1
- data/lib/string-text.rb +23 -3
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cb6091be55dccdd85e5ed00b7348573a768833a782725e00a0aa6258506c31b
|
4
|
+
data.tar.gz: 5faa4885c3a303f1eed4ee21ad30a80b779701df7be15be9fda079ea353d9c3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee4799f3ac56b221c362e00c6627282aa03dcf294af5ce88422e3134c60fa96e5d3d25eb2bbbe09ad5720a7890e205beb7bfb34c91efb22122f4e64eeead656b
|
7
|
+
data.tar.gz: 8ebb89255417583f8dc30ec33ca08db50d2ea88a748c186cf95d6bf3df511eb6a6ae84d1502c077277c7585a17f569333b855210b054ba503df7e3d67a7fcebe
|
data/lib/string-text/version.rb
CHANGED
data/lib/string-text.rb
CHANGED
@@ -19,22 +19,42 @@ module String::Text
|
|
19
19
|
# This line will start at column 3
|
20
20
|
# ).align
|
21
21
|
#
|
22
|
-
|
22
|
+
# If :bol is false then the first line won't be indented or outdented. It
|
23
|
+
# is used when including a block of text in another block:
|
24
|
+
#
|
25
|
+
# innert_text = %(
|
26
|
+
# first line
|
27
|
+
# second line
|
28
|
+
# )
|
29
|
+
# puts %(
|
30
|
+
# Here is the outer text
|
31
|
+
# #{inner_text.align(2, bol: false)}
|
32
|
+
# Rest of the outer text
|
33
|
+
# ).align
|
34
|
+
#
|
35
|
+
def align(column = 1, bol: true)
|
23
36
|
column > 0 or raise ArgumentError "Illegal column: #{column}"
|
24
37
|
initial = " " * (column - 1)
|
25
38
|
lines = self.split(/\n/)
|
26
39
|
lines.pop while !lines.empty? && !(lines.last =~ /^\s*\S/)
|
27
40
|
lines.shift while !lines.empty? && !(lines.first =~ /^\s*\S/)
|
28
41
|
return "" if lines.empty?
|
42
|
+
|
29
43
|
indent = lines.map { _1 =~ /^(\s*)/; $1.size }.select { _1 > 0 }.min || 0
|
44
|
+
first = true
|
30
45
|
lines.map { |line|
|
31
46
|
l = line[indent..-1]&.rstrip
|
32
|
-
|
47
|
+
if !bol && first
|
48
|
+
first = false
|
49
|
+
l || ""
|
50
|
+
else
|
51
|
+
l ? initial + l : ""
|
52
|
+
end
|
33
53
|
}.join("\n")
|
34
54
|
end
|
35
55
|
|
36
56
|
# Like #align but replaces the string
|
37
|
-
def align!(column = 1) = self.replace align(column)
|
57
|
+
def align!(column = 1, bol: true) = self.replace align(column, bol: bol)
|
38
58
|
|
39
59
|
# Converts a string to a boolean so that "true" becomes true and that
|
40
60
|
# "false" and the empty string becomes false. Any other string is an error
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string-text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: Gem string-text
|
14
13
|
email:
|
@@ -30,7 +29,6 @@ homepage: http://www.nowhere.com/
|
|
30
29
|
licenses: []
|
31
30
|
metadata:
|
32
31
|
homepage_uri: http://www.nowhere.com/
|
33
|
-
post_install_message:
|
34
32
|
rdoc_options: []
|
35
33
|
require_paths:
|
36
34
|
- lib
|
@@ -45,8 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
43
|
- !ruby/object:Gem::Version
|
46
44
|
version: '0'
|
47
45
|
requirements: []
|
48
|
-
rubygems_version: 3.
|
49
|
-
signing_key:
|
46
|
+
rubygems_version: 3.6.9
|
50
47
|
specification_version: 4
|
51
48
|
summary: Text formatting methods
|
52
49
|
test_files: []
|