dedent 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -0
- data/lib/dedent.rb +5 -2
- data/lib/dedent/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -40,6 +40,13 @@ for f in $(ls /foo/bar/); do
|
|
40
40
|
done
|
41
41
|
```
|
42
42
|
|
43
|
+
One thing to note is that lines with no non-whitespaces characters are not considered when determining the
|
44
|
+
indentation of a text block:
|
45
|
+
|
46
|
+
```
|
47
|
+
"\n foo".dedent # => "\nfoo"
|
48
|
+
```
|
49
|
+
|
43
50
|
Author
|
44
51
|
------
|
45
52
|
|
data/lib/dedent.rb
CHANGED
@@ -4,8 +4,11 @@ class String
|
|
4
4
|
def dedent
|
5
5
|
lines = split "\n"
|
6
6
|
return self if lines.empty?
|
7
|
-
|
7
|
+
indents = lines.map do |line|
|
8
|
+
line =~ /\S/ ? (line.start_with?(" ") ? line.match(/^ +/).offset(0)[1] : 0) : nil
|
9
|
+
end
|
10
|
+
min_indent = indents.compact.min
|
8
11
|
return self if min_indent.zero?
|
9
|
-
lines.map { |line| line.gsub(/^ {#{min_indent}}/, "") }.join
|
12
|
+
lines.map { |line| line =~ /\S/ ? line.gsub(/^ {#{min_indent}}/, "") : line }.join "\n"
|
10
13
|
end
|
11
14
|
end
|
data/lib/dedent/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dedent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-08 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'This gem adds a dedent method to strings to strip leading spaces from
|
15
15
|
each line while preserving indentation.
|