string-text 0.1.0 → 0.2.1

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: 2c8877c7f9cb5cfe2d0dc601b570a010b4ff24b5cebcb374ac3b7ae0bff4dfb5
4
- data.tar.gz: 589a2cca9d6850e4c9fb08f1d504db2377fcd82f781a728867ac26a90cd7d65f
3
+ metadata.gz: ef4d50e5bf3891bbbeb0e9c85550bfe11b978843594f5ce6473800c7aa0b8da7
4
+ data.tar.gz: 6092c921901c893fbdfdb523a979003af64bbee0e57c1c31018d9f17f5d3c73a
5
5
  SHA512:
6
- metadata.gz: 61da90d76afcbbf88ddc44ea0eaedf28ef986d8aa5f2f0281377fa8af073f553cb28d899d2a6ea363e63dcf5c854b681538f5bad4c86d948d68984ccba025bcb
7
- data.tar.gz: c8b4e49cd741aeee1293bef948c732f9ce98a264cb89f4b6d61319d355d56290882d525968054ebfb661b9e6698cb9d17597b234c4aa7319fc930b1cf0aba899
6
+ metadata.gz: 611f496cdc55ecfb9adff70ee277782f0e8a948563efb2041d97f61b597722e9e9b091baa3d9955d69d6363e2c4bd1e55ba7df28c10ec3042b45f3961dfad9e5
7
+ data.tar.gz: 53a0a44cca61fcd5fe7c88ebf4c953dfa84e3e0a95fef9829cdb85d609a28e6ed2113fa3a2bdd3beb3c54761f0960847eab1f71637a0ddb7a642b830dcaeb783
data/TODO ADDED
@@ -0,0 +1,12 @@
1
+
2
+ TODO
3
+ + Rename #undent -> #align
4
+
5
+ IDEA
6
+ string-ext_text
7
+ string-ext_to_b
8
+
9
+ lib/<project>/ext/string.rb
10
+ -> require 'string-ext/text.rb'
11
+ require 'string-ext/to_b.rb'
12
+
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module String::Text
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/string-text.rb CHANGED
@@ -6,23 +6,32 @@ module String::Text
6
6
  class Error < StandardError; end
7
7
 
8
8
  refine String do
9
- def undent
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
13
+ #
14
+ # #align is often handy when you call methods with a %(...) argument
15
+ # and don't want weird indentation in your output
16
+ #
17
+ # puts %(
18
+ # This line will start at column 1
19
+ # This line will start at column 3
20
+ # ).align
21
+ #
22
+ def align(column = 1)
23
+ column == 1 or raise NotImplementedError
10
24
  lines = self.split(/\n/)
25
+ lines.pop while !lines.empty? && !(lines.last =~ /^\s*\S/)
11
26
  lines.shift while !lines.empty? && !(lines.first =~ /^(\s*)\S/)
12
27
  return "" if lines.empty?
13
28
  indent = $1.size
14
- r = []
15
- while line = lines.shift&.rstrip
16
- r << (line[indent..-1] || "")
17
- end
18
- while !r.empty? && r.last =~ /^\s*$/
19
- r.pop
20
- end
21
- r.join("\n").chomp
29
+ lines.map { |line| line[indent..-1].rstrip || "" }.join("\n")
22
30
  end
23
31
 
24
- # Converts a string to a boolean so that "true" becomes true and "false" and
25
- # the empty string becomes false. Should actually go in to a
32
+ # Converts a string to a boolean so that "true" becomes true and that
33
+ # "false" and the empty string becomes false. Any other string is an error
34
+ #
26
35
  def to_b
27
36
  case self
28
37
  when "true"; true
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.1.0
4
+ version: 0.2.1
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-04-25 00:00:00.000000000 Z
11
+ date: 2024-06-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Gem string-text
14
14
  email:
@@ -22,6 +22,7 @@ files:
22
22
  - Gemfile
23
23
  - README.md
24
24
  - Rakefile
25
+ - TODO
25
26
  - lib/string-text.rb
26
27
  - lib/string-text/version.rb
27
28
  - sig/string_text.rbs