lstrip-on-steroids 0.9 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/lstrip_on_steroids.rb +30 -5
  3. metadata +4 -3
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require "rake/gempackagetask"
2
2
 
3
3
  spec = Gem::Specification.new do |s|
4
4
  s.name = "lstrip-on-steroids"
5
- s.version = "0.9"
5
+ s.version = "0.9.5"
6
6
  s.author = "Caius Durling"
7
7
  s.email = "dev@caius.name"
8
8
  s.homepage = "http://github.com/caius/lstrip-on-steroids"
@@ -1,10 +1,35 @@
1
1
  module LStripOnSteroids
2
+ class JuicedStripper
3
+ def initialize lines
4
+ @lines = lines
5
+ strip_bare_top_and_bottom
6
+ end
7
+
8
+ def strip
9
+ @lines.map {|line| line.sub(/^ {#{whitespace_trim_length}}/, "") }
10
+ end
11
+
12
+ private
13
+
14
+ def whitespace_trim_length
15
+ @whitespace_trim_length ||= @lines.map {|line| indent_size(line) }.min
16
+ end
17
+
18
+ def strip_bare_top_and_bottom
19
+ [0, -1].each {|i| @lines.delete_at(i) if bare?(@lines[i]) }
20
+ end
21
+
22
+ def indent_size line
23
+ line.match(/^ */)[0].length
24
+ end
25
+
26
+ def bare? line
27
+ line[/^ *$/]
28
+ end
29
+ end
30
+
2
31
  def -@
3
- lines = split("\n")[1...-1]
4
- leading_whitespace = lines.map { |line| line.match(/^ */)[0].length }.min
5
- lines.map { |line|
6
- line.sub(/^ {#{leading_whitespace}}/, "")
7
- }.join("\n")
32
+ JuicedStripper.new(split("\n")).strip.join("\n")
8
33
  end
9
34
  end
10
35
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lstrip-on-steroids
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 49
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- version: "0.9"
9
+ - 5
10
+ version: 0.9.5
10
11
  platform: ruby
11
12
  authors:
12
13
  - Caius Durling
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-08-19 00:00:00 +01:00
18
+ date: 2010-08-20 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies: []
20
21