unindentable 0.0.1 → 0.0.2

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.
@@ -10,14 +10,24 @@ module Unindentable
10
10
  # Returns the indent level of a string (with multiple lines)
11
11
  def find_minimum_indent(string)
12
12
  indents = []
13
- string.each_line { |l| indents << l.index(/[^ ]/) }
13
+ string.each_line do |line|
14
+ unless line == "\n"
15
+ indents << line.index(/[^ ]/)
16
+ end
17
+ end
14
18
  indents.min
15
19
  end
16
20
 
17
21
  # Trims the leftmost n characters from each line of a string
18
22
  def left_trim(string, n)
19
23
  new_string = ""
20
- string.each_line { |l| new_string << l.slice(n, l.length) }
24
+ string.each_line do |line|
25
+ new_string << if line == "\n"
26
+ "\n"
27
+ else
28
+ line.slice(n, line.length)
29
+ end
30
+ end
21
31
  new_string
22
32
  end
23
33
 
@@ -63,4 +63,13 @@ c
63
63
  x.should == "The first line\n The second line\n \nThe fourth line\n"
64
64
  end
65
65
 
66
+ it "should not let blank lines break the indent" do
67
+ x = unindent <<-BLOCK
68
+ The first line
69
+
70
+ The third line
71
+ BLOCK
72
+ x.should == "The first line\n\nThe third line\n"
73
+ end
74
+
66
75
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unindentable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - David James
@@ -41,18 +46,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
41
46
  requirements:
42
47
  - - ">="
43
48
  - !ruby/object:Gem::Version
49
+ segments:
50
+ - 0
44
51
  version: "0"
45
- version:
46
52
  required_rubygems_version: !ruby/object:Gem::Requirement
47
53
  requirements:
48
54
  - - ">="
49
55
  - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
50
58
  version: "0"
51
- version:
52
59
  requirements: []
53
60
 
54
61
  rubyforge_project:
55
- rubygems_version: 1.3.5
62
+ rubygems_version: 1.3.6
56
63
  signing_key:
57
64
  specification_version: 3
58
65
  summary: With Unindentable, you can write heredocs without worry of wonky indentation.