string-text 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed317a1e41b961f812910fc9f82664692615953dba53a39ac117c3dc706e8fbc
4
- data.tar.gz: 83426aa78c20ed366b7c525dbbc66ac684ac7d1238d4b8abe7f50124b545de42
3
+ metadata.gz: 966183d6fa9a4ab3f04278e9f0e22c5c85cc704b3a82c5d9271f065d5968905b
4
+ data.tar.gz: 0bc9b6cf81c86bc1e0104b3fbe95e000c14a4983ce8ed311eb2a9dfc0b21063c
5
5
  SHA512:
6
- metadata.gz: dc43bac8d3c17c6026dfb1bc664bdfa97d2c444632b1736811b5151cad1addaf9c240ad588fb2d892febaa465367d1de9b470e2137de78802a0174b79c5898d3
7
- data.tar.gz: 2f3a125f542cd525cc5f341a1d4570a5190926df1b795dac86babbd98889ddc247cb5f80017868c4010f8593e0e7e898443d0cc05ca7544676cb93995a454aa5
6
+ metadata.gz: 185b584f5adabc6a82bcfcb191cd2ea6ba6e2fb364e95ab273c3f4beb20a581dfe859a1c08788946539369c008770f14cb4e600be23ea78484c69651d98aaa0a
7
+ data.tar.gz: c446c492db325e861e86f308cb924d2adfdc3f2a6320e0a4aa771d61621302c92a5bdcd7c8814d272c6cc98895ed8712f95f4c93e704dfe58559c8d6db258d14
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module String::Text
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
data/lib/string-text.rb CHANGED
@@ -6,10 +6,10 @@ module String::Text
6
6
  class Error < StandardError; end
7
7
 
8
8
  refine String do
9
- # Indent or outdent a block of text to the given column. It uses the indent
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.
12
- # Initial and final empty lines are ignored
9
+ # Indent or outdent a block of text to the given column (default 1). It
10
+ # uses the indent of the least indented non-empty line as the indent of the
11
+ # whole block that is then aligned as a whole (including internal indents)
12
+ # to the given column. Initial and final empty lines are ignored
13
13
  #
14
14
  # #align is often handy when you call methods with a %(...) argument
15
15
  # and don't want weird indentation in your output
@@ -23,9 +23,9 @@ module String::Text
23
23
  column == 1 or raise NotImplementedError
24
24
  lines = self.split(/\n/)
25
25
  lines.pop while !lines.empty? && !(lines.last =~ /^\s*\S/)
26
- lines.shift while !lines.empty? && !(lines.first =~ /^(\s*)\S/)
26
+ lines.shift while !lines.empty? && !(lines.first =~ /^\s*\S/)
27
27
  return "" if lines.empty?
28
- indent = $1.size
28
+ indent = lines.map { _1 =~ /^(\s*)/; $1.size }.select { _1 > 0 }.min || 0
29
29
  lines.map { |line| line[indent..-1]&.rstrip || "" }.join("\n")
30
30
  end
31
31
 
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.2
4
+ version: 0.2.3
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-11 00:00:00.000000000 Z
11
+ date: 2024-06-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Gem string-text
14
14
  email: