string-text 0.7.1 → 0.8.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 +5 -4
- 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: 5a74a791dce540de25e15aee87d46ffad13b6b681dd900a5abf64c3b18106169
|
4
|
+
data.tar.gz: 775033ab62489346e7334c9935ae0555e170c94ff4c94418039b4e0624abe86e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26f2d2c4d7085fedc90010cab5f1c96b0694b3124c53205e9fcc022a07aa893734aecdb3a5a3330d95282cdb8b8a51990cc0e42e1f9f0c3ad3fae43b8a09e94d
|
7
|
+
data.tar.gz: 95827c43612d432f7dd33d594a2201d754f8f3420bdc683e0be923bc72b9637fa9b3b894fde8958729cc827b0a2e2e8a0178d91a74533585f21932cc3a6f95a6
|
data/lib/string-text/version.rb
CHANGED
data/lib/string-text.rb
CHANGED
@@ -5,8 +5,6 @@ require_relative "string-text/version"
|
|
5
5
|
module String::Text
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
8
|
-
def self.indentation(s) s =~ /^(\s*)/; $1.size end
|
9
|
-
|
10
8
|
refine String do
|
11
9
|
# Indent or outdent a block of text to the given column (default 1). It
|
12
10
|
# uses the indent of the least indented non-empty line as the indent of the
|
@@ -68,12 +66,12 @@ module String::Text
|
|
68
66
|
return lines.map { "" }.join("\n") if line.nil?
|
69
67
|
|
70
68
|
# Only align to given column if first line is not indented
|
71
|
-
if
|
69
|
+
if line.indentation == 0
|
72
70
|
return lines.map { |line| ' ' * (column-1) + line }.join("\n")
|
73
71
|
end
|
74
72
|
|
75
73
|
# Identation level of each line
|
76
|
-
indents = lines.map
|
74
|
+
indents = lines.map(&:indentation)
|
77
75
|
|
78
76
|
# Find minimal indent, ignoring unindented lines
|
79
77
|
indent = indents.select { _1 > 0 }.min || 0
|
@@ -99,6 +97,9 @@ module String::Text
|
|
99
97
|
# Like #align but replaces the string
|
100
98
|
def align!(column = 1, bol: true) = self.replace align(column, bol: bol)
|
101
99
|
|
100
|
+
# Indent of line
|
101
|
+
def indentation = (self[/\A *\S/]&.size || 1) - 1
|
102
|
+
|
102
103
|
# Converts a string to a boolean so that "true" becomes true and that
|
103
104
|
# "false" and the empty string becomes false. Any other string is an error
|
104
105
|
#
|