string-text 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbebbdbd77112e3f5322cd1bc2e1296c06cc0e4106dbb2b59cfa71e41e869f93
4
- data.tar.gz: 883ad7d37349a4a0b7851006d19292e46c4a9628a63daba9011fd8283b782bde
3
+ metadata.gz: 9cb6091be55dccdd85e5ed00b7348573a768833a782725e00a0aa6258506c31b
4
+ data.tar.gz: 5faa4885c3a303f1eed4ee21ad30a80b779701df7be15be9fda079ea353d9c3b
5
5
  SHA512:
6
- metadata.gz: 37879cfee303951695df37ba4a110a3020a3d8b769fb0e1ed48607aea1912d8c1ef4085bed452b881422e2a687e2e46a050f33bb8adc577a3eaaeafdbd1b8f45
7
- data.tar.gz: f32f7e8b5146b90f763e8a68301be62d37354f640b6882364334ba64d741f56ee2eac35cb78a37e8b319cf2d679c94ec90fa0bb0a16d1d4ed3381556f4eb27d2
6
+ metadata.gz: ee4799f3ac56b221c362e00c6627282aa03dcf294af5ce88422e3134c60fa96e5d3d25eb2bbbe09ad5720a7890e205beb7bfb34c91efb22122f4e64eeead656b
7
+ data.tar.gz: 8ebb89255417583f8dc30ec33ca08db50d2ea88a748c186cf95d6bf3df511eb6a6ae84d1502c077277c7585a17f569333b855210b054ba503df7e3d67a7fcebe
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module String::Text
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/string-text.rb CHANGED
@@ -19,22 +19,42 @@ module String::Text
19
19
  # This line will start at column 3
20
20
  # ).align
21
21
  #
22
- def align(column = 1)
22
+ # If :bol is false then the first line won't be indented or outdented. It
23
+ # is used when including a block of text in another block:
24
+ #
25
+ # innert_text = %(
26
+ # first line
27
+ # second line
28
+ # )
29
+ # puts %(
30
+ # Here is the outer text
31
+ # #{inner_text.align(2, bol: false)}
32
+ # Rest of the outer text
33
+ # ).align
34
+ #
35
+ def align(column = 1, bol: true)
23
36
  column > 0 or raise ArgumentError "Illegal column: #{column}"
24
37
  initial = " " * (column - 1)
25
38
  lines = self.split(/\n/)
26
39
  lines.pop while !lines.empty? && !(lines.last =~ /^\s*\S/)
27
40
  lines.shift while !lines.empty? && !(lines.first =~ /^\s*\S/)
28
41
  return "" if lines.empty?
42
+
29
43
  indent = lines.map { _1 =~ /^(\s*)/; $1.size }.select { _1 > 0 }.min || 0
44
+ first = true
30
45
  lines.map { |line|
31
46
  l = line[indent..-1]&.rstrip
32
- l ? initial + l : ""
47
+ if !bol && first
48
+ first = false
49
+ l || ""
50
+ else
51
+ l ? initial + l : ""
52
+ end
33
53
  }.join("\n")
34
54
  end
35
55
 
36
56
  # Like #align but replaces the string
37
- def align!(column = 1) = self.replace align(column)
57
+ def align!(column = 1, bol: true) = self.replace align(column, bol: bol)
38
58
 
39
59
  # Converts a string to a boolean so that "true" becomes true and that
40
60
  # "false" and the empty string becomes false. Any other string is an error
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string-text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-09-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Gem string-text
14
13
  email:
@@ -30,7 +29,6 @@ homepage: http://www.nowhere.com/
30
29
  licenses: []
31
30
  metadata:
32
31
  homepage_uri: http://www.nowhere.com/
33
- post_install_message:
34
32
  rdoc_options: []
35
33
  require_paths:
36
34
  - lib
@@ -45,8 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
43
  - !ruby/object:Gem::Version
46
44
  version: '0'
47
45
  requirements: []
48
- rubygems_version: 3.3.7
49
- signing_key:
46
+ rubygems_version: 3.6.9
50
47
  specification_version: 4
51
48
  summary: Text formatting methods
52
49
  test_files: []