string-text 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/string-text/version.rb +1 -1
- data/lib/string-text.rb +6 -11
- 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: ef4d50e5bf3891bbbeb0e9c85550bfe11b978843594f5ce6473800c7aa0b8da7
|
4
|
+
data.tar.gz: 6092c921901c893fbdfdb523a979003af64bbee0e57c1c31018d9f17f5d3c73a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 611f496cdc55ecfb9adff70ee277782f0e8a948563efb2041d97f61b597722e9e9b091baa3d9955d69d6363e2c4bd1e55ba7df28c10ec3042b45f3961dfad9e5
|
7
|
+
data.tar.gz: 53a0a44cca61fcd5fe7c88ebf4c953dfa84e3e0a95fef9829cdb85d609a28e6ed2113fa3a2bdd3beb3c54761f0960847eab1f71637a0ddb7a642b830dcaeb783
|
data/lib/string-text/version.rb
CHANGED
data/lib/string-text.rb
CHANGED
@@ -8,10 +8,11 @@ module String::Text
|
|
8
8
|
refine String do
|
9
9
|
# Indent or outdent a block of text to the given column. It uses the indent
|
10
10
|
# of the non-empty line as the indent of the whole block that is then
|
11
|
-
# aligned as a whole (including internal indents) to the given column
|
11
|
+
# aligned as a whole (including internal indents) to the given column.
|
12
|
+
# Initial and final empty lines are ignored
|
12
13
|
#
|
13
|
-
#
|
14
|
-
# don't want weird indentation in your output
|
14
|
+
# #align is often handy when you call methods with a %(...) argument
|
15
|
+
# and don't want weird indentation in your output
|
15
16
|
#
|
16
17
|
# puts %(
|
17
18
|
# This line will start at column 1
|
@@ -21,17 +22,11 @@ module String::Text
|
|
21
22
|
def align(column = 1)
|
22
23
|
column == 1 or raise NotImplementedError
|
23
24
|
lines = self.split(/\n/)
|
25
|
+
lines.pop while !lines.empty? && !(lines.last =~ /^\s*\S/)
|
24
26
|
lines.shift while !lines.empty? && !(lines.first =~ /^(\s*)\S/)
|
25
27
|
return "" if lines.empty?
|
26
28
|
indent = $1.size
|
27
|
-
|
28
|
-
while line = lines.shift&.rstrip
|
29
|
-
r << (line[indent..-1] || "")
|
30
|
-
end
|
31
|
-
while !r.empty? && r.last =~ /^\s*$/
|
32
|
-
r.pop
|
33
|
-
end
|
34
|
-
r.join("\n").chomp
|
29
|
+
lines.map { |line| line[indent..-1].rstrip || "" }.join("\n")
|
35
30
|
end
|
36
31
|
|
37
32
|
# Converts a string to a boolean so that "true" becomes true and that
|