string-text 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d954b59921214f791a82b0e1d07eb5ff770005d512fbdf231eb9e0d8c5ff7d3
4
- data.tar.gz: 79350075e64dd1277b5a2b5610b8df9fb7c05a3e64ea90c1c4e5a6460e2f4471
3
+ metadata.gz: ed317a1e41b961f812910fc9f82664692615953dba53a39ac117c3dc706e8fbc
4
+ data.tar.gz: 83426aa78c20ed366b7c525dbbc66ac684ac7d1238d4b8abe7f50124b545de42
5
5
  SHA512:
6
- metadata.gz: 18c9a7a0ed48c3ab51257983bb245a5087770594bbd9d20e283611846a6fce42f52af5976ef8157e572e0b6f772aa3746b321ea5d2968cfc28776775d77ae055
7
- data.tar.gz: 037437d4642ac34a171127bce254162d230437047870847216322eed0be5b3269a6242a55f5cc00c0fe453cedb710a35874413693be8f22e8e1ff39da229075c
6
+ metadata.gz: dc43bac8d3c17c6026dfb1bc664bdfa97d2c444632b1736811b5151cad1addaf9c240ad588fb2d892febaa465367d1de9b470e2137de78802a0174b79c5898d3
7
+ data.tar.gz: 2f3a125f542cd525cc5f341a1d4570a5190926df1b795dac86babbd98889ddc247cb5f80017868c4010f8593e0e7e898443d0cc05ca7544676cb93995a454aa5
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module String::Text
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.2"
5
5
  end
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
- # It is often handy when you're calling methods with a %(...) argument and
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
- r = []
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
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.2.0
4
+ version: 0.2.2
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-06-05 00:00:00.000000000 Z
11
+ date: 2024-06-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Gem string-text
14
14
  email: