string-text 0.7.1 → 0.8.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: 236f0b891ea63167b6c15dc8b95e005522111fbb26b1da528778a20914756c2e
4
- data.tar.gz: 2edc82881d923ff63f33970bb32e28798bdd5966dcc2aad0f5c3e6e1d65a0ce7
3
+ metadata.gz: 5a74a791dce540de25e15aee87d46ffad13b6b681dd900a5abf64c3b18106169
4
+ data.tar.gz: 775033ab62489346e7334c9935ae0555e170c94ff4c94418039b4e0624abe86e
5
5
  SHA512:
6
- metadata.gz: 9bfa8242ea5465ccede62e64829e9c9b23c476b5c14c94fbdf97e8193b8e36f6122d785f789d067ced8c16b493252aa65d8ad2ab0970e859213f4a54377b8174
7
- data.tar.gz: 6b1771f38533968c69fcf544aeba90dffb61aacd753ae929c03a349fa7b00a99fabcd10201a9a4be2da4f24e99a35e44f0e3e33f6d63be19bb4840f79b03eabb
6
+ metadata.gz: 26f2d2c4d7085fedc90010cab5f1c96b0694b3124c53205e9fcc022a07aa893734aecdb3a5a3330d95282cdb8b8a51990cc0e42e1f9f0c3ad3fae43b8a09e94d
7
+ data.tar.gz: 95827c43612d432f7dd33d594a2201d754f8f3420bdc683e0be923bc72b9637fa9b3b894fde8958729cc827b0a2e2e8a0178d91a74533585f21932cc3a6f95a6
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module String::Text
4
- VERSION = "0.7.1"
4
+ VERSION = "0.8.0"
5
5
  end
data/lib/string-text.rb CHANGED
@@ -5,8 +5,6 @@ require_relative "string-text/version"
5
5
  module String::Text
6
6
  class Error < StandardError; end
7
7
 
8
- def self.indentation(s) s =~ /^(\s*)/; $1.size end
9
-
10
8
  refine String do
11
9
  # Indent or outdent a block of text to the given column (default 1). It
12
10
  # uses the indent of the least indented non-empty line as the indent of the
@@ -68,12 +66,12 @@ module String::Text
68
66
  return lines.map { "" }.join("\n") if line.nil?
69
67
 
70
68
  # Only align to given column if first line is not indented
71
- if String::Text.indentation(line) == 0
69
+ if line.indentation == 0
72
70
  return lines.map { |line| ' ' * (column-1) + line }.join("\n")
73
71
  end
74
72
 
75
73
  # Identation level of each line
76
- indents = lines.map { String::Text.indentation(_1) }
74
+ indents = lines.map(&:indentation)
77
75
 
78
76
  # Find minimal indent, ignoring unindented lines
79
77
  indent = indents.select { _1 > 0 }.min || 0
@@ -99,6 +97,9 @@ module String::Text
99
97
  # Like #align but replaces the string
100
98
  def align!(column = 1, bol: true) = self.replace align(column, bol: bol)
101
99
 
100
+ # Indent of line
101
+ def indentation = (self[/\A *\S/]&.size || 1) - 1
102
+
102
103
  # Converts a string to a boolean so that "true" becomes true and that
103
104
  # "false" and the empty string becomes false. Any other string is an error
104
105
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string-text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen