freighthopper 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/freighthopper/string/unindent.rb +5 -1
- data/test/string_test.rb +4 -0
- metadata +4 -4
@@ -4,7 +4,11 @@ class String
|
|
4
4
|
lines = gsub("\t", " " * tablength).split("\n")
|
5
5
|
|
6
6
|
whitespace = lines.map do |line|
|
7
|
-
line.match(/^(\s+)/)
|
7
|
+
if match = line.match(/^(\s+)/)
|
8
|
+
match.captures.first
|
9
|
+
else
|
10
|
+
""
|
11
|
+
end
|
8
12
|
end.min{ |l, r| l.length <=> r.length }
|
9
13
|
|
10
14
|
lines.map{ |l| l.gsub /^#{whitespace}/, ''}.join("\n")
|
data/test/string_test.rb
CHANGED
@@ -44,6 +44,10 @@ class StringTest < Test::Unit::TestCase
|
|
44
44
|
|
45
45
|
assert_equal "a\n b\n c", unindented
|
46
46
|
end
|
47
|
+
|
48
|
+
should 'work with blank lines' do
|
49
|
+
assert_equal "test", "test".unindent
|
50
|
+
end
|
47
51
|
|
48
52
|
should 'replace tabs with tablength' do
|
49
53
|
unindented = "\ttest\n\t\ttest".unindent :tablength => 4
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freighthopper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 13
|
10
|
+
version: 0.1.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jacob Rothstein
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-06 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|