string-text 0.2.3 → 0.4.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 +10 -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: bbebbdbd77112e3f5322cd1bc2e1296c06cc0e4106dbb2b59cfa71e41e869f93
|
4
|
+
data.tar.gz: 883ad7d37349a4a0b7851006d19292e46c4a9628a63daba9011fd8283b782bde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37879cfee303951695df37ba4a110a3020a3d8b769fb0e1ed48607aea1912d8c1ef4085bed452b881422e2a687e2e46a050f33bb8adc577a3eaaeafdbd1b8f45
|
7
|
+
data.tar.gz: f32f7e8b5146b90f763e8a68301be62d37354f640b6882364334ba64d741f56ee2eac35cb78a37e8b319cf2d679c94ec90fa0bb0a16d1d4ed3381556f4eb27d2
|
data/lib/string-text/version.rb
CHANGED
data/lib/string-text.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative "string-text/version"
|
|
4
4
|
|
5
5
|
module String::Text
|
6
6
|
class Error < StandardError; end
|
7
|
-
|
7
|
+
|
8
8
|
refine String do
|
9
9
|
# Indent or outdent a block of text to the given column (default 1). It
|
10
10
|
# uses the indent of the least indented non-empty line as the indent of the
|
@@ -20,15 +20,22 @@ module String::Text
|
|
20
20
|
# ).align
|
21
21
|
#
|
22
22
|
def align(column = 1)
|
23
|
-
column
|
23
|
+
column > 0 or raise ArgumentError "Illegal column: #{column}"
|
24
|
+
initial = " " * (column - 1)
|
24
25
|
lines = self.split(/\n/)
|
25
26
|
lines.pop while !lines.empty? && !(lines.last =~ /^\s*\S/)
|
26
27
|
lines.shift while !lines.empty? && !(lines.first =~ /^\s*\S/)
|
27
28
|
return "" if lines.empty?
|
28
29
|
indent = lines.map { _1 =~ /^(\s*)/; $1.size }.select { _1 > 0 }.min || 0
|
29
|
-
lines.map { |line|
|
30
|
+
lines.map { |line|
|
31
|
+
l = line[indent..-1]&.rstrip
|
32
|
+
l ? initial + l : ""
|
33
|
+
}.join("\n")
|
30
34
|
end
|
31
35
|
|
36
|
+
# Like #align but replaces the string
|
37
|
+
def align!(column = 1) = self.replace align(column)
|
38
|
+
|
32
39
|
# Converts a string to a boolean so that "true" becomes true and that
|
33
40
|
# "false" and the empty string becomes false. Any other string is an error
|
34
41
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string-text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Gem string-text
|
14
14
|
email:
|