dedent 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3693cab618105e14872dcb7e9d18c7c39ba474df
4
- data.tar.gz: 608624e0e261db6877fb9e2b6d65d277ad258fd5
3
+ metadata.gz: a371ad9f527323dafe40ce81fb664082d7da9977
4
+ data.tar.gz: 7ac909a290104e282f23361ab9c383187b46a4fe
5
5
  SHA512:
6
- metadata.gz: 31a73fddf17b8991d6236d2219595f1f12770620a74787d15878f548003b4fb937623c50fb74a00ecfc0726c096590bf3acd093f456a6742a70314bdaed9b99c
7
- data.tar.gz: c27f770c0fafa6f8f979d2bdc0a688b9e918f2cf5c728c5a4eadf0fb29d1535f1193e63b534c481452bcf880e0576b51da31655cd4675c6edb7d748c54144445
6
+ metadata.gz: a0e88c6202834e58699db7408dfe8f9ee9f14733f6bb92cd18cd4cd6c3b93b446f0773313dd715fac6524cad931c2aa67aa0ec8d97bd6daf5ee4bb5b666d6833
7
+ data.tar.gz: 692d6df9af7f4f64eaca3597f929ad28ed7bd4d1b10ab09c83bfa4c57f13b6c2d59da9ea20cd5cf7624a0879856a93d624c336096e50b39d27c0a2870d3d77de
data/README.md CHANGED
@@ -6,7 +6,7 @@ Installation
6
6
 
7
7
  gem install dedent
8
8
 
9
- Only tested with Ruby 1.9.2 and 1.8.7.
9
+ Tested with Ruby 1.9.3 and 2.1.1.
10
10
 
11
11
  Usage
12
12
  -----
@@ -15,9 +15,9 @@ This is a tiny gem that adds the `dedent` method to String. This method strips l
15
15
  line, preserving indentation. So, the line with the least amount of leading whitespace will have all leading
16
16
  whitespace removed, while other lines will have whitespace relative to that line's offset.
17
17
 
18
- The main use of this is with heredocs. It can be annoying because even with the `<<-` form of heredocs, all
19
- the initial whitespace on each line of the string is preserved, so if you keep the string in the same
20
- indentation as the code, you end up with a bunch of extra space.
18
+ The main use of this is with heredocs. It can be annoying because even with the `<<-` form, all the initial
19
+ whitespace on each line of the string is preserved, so if you keep the string in the same indentation as the
20
+ code, you end up with extra space.
21
21
 
22
22
  Here's an example of using dedent with heredocs:
23
23
 
@@ -40,7 +40,7 @@ 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
43
+ One thing to note is that lines with no non-whitespace characters are not considered when determining the
44
44
  indentation of a text block:
45
45
 
46
46
  ```
@@ -20,4 +20,6 @@ This gem adds a dedent method to strings to strip leading spaces from each line
20
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
+
24
+ s.add_development_dependency "minitest"
23
25
  end
@@ -1,5 +1,3 @@
1
- require "dedent/version"
2
-
3
1
  class String
4
2
  def dedent
5
3
  lines = split "\n"
@@ -7,7 +5,12 @@ class String
7
5
  indents = lines.map do |line|
8
6
  line =~ /\S/ ? (line.start_with?(" ") ? line.match(/^ +/).offset(0)[1] : 0) : nil
9
7
  end
10
- min_indent = indents.compact.min
8
+ indents.compact!
9
+ if indents.empty?
10
+ # No lines had any non-whitespace characters.
11
+ return ([""] * lines.size).join "\n"
12
+ end
13
+ min_indent = indents.min
11
14
  return self if min_indent.zero?
12
15
  lines.map { |line| line =~ /\S/ ? line.gsub(/^ {#{min_indent}}/, "") : line }.join "\n"
13
16
  end
@@ -1,3 +1,3 @@
1
1
  module Dedent
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -0,0 +1,43 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "../lib")
2
+ require "minitest/autorun"
3
+ require "minitest"
4
+ require "dedent"
5
+
6
+ class DedentTest < Minitest::Test
7
+ def test_basic
8
+ assert_equal "foobar", " foobar".dedent
9
+ end
10
+
11
+ def test_whitespace
12
+ assert_equal "", "".dedent
13
+ assert_equal "", " ".dedent
14
+ assert_equal "", " \n".dedent
15
+ assert_equal "\n", " \n ".dedent
16
+ end
17
+
18
+ def test_multiple_lines
19
+ s = <<-EOF
20
+ foo
21
+ bar
22
+ baz
23
+ EOF
24
+ assert_equal "foo\nbar\nbaz", s.dedent
25
+ end
26
+
27
+ def test_indented
28
+ s = <<-EOF
29
+ foo
30
+ bar
31
+ baz
32
+ EOF
33
+ assert_equal "foo\n bar\n baz", s.dedent
34
+ end
35
+
36
+ def test_zero_indent
37
+ s = <<EOF
38
+ foo
39
+ bar
40
+ EOF
41
+ assert_equal "foo\n bar\n", s.dedent
42
+ end
43
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dedent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Spare
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-16 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: |
14
28
  This gem adds a dedent method to strings to strip leading spaces from each line while preserving indentation.
15
29
  email:
@@ -18,7 +32,7 @@ executables: []
18
32
  extensions: []
19
33
  extra_rdoc_files: []
20
34
  files:
21
- - .gitignore
35
+ - ".gitignore"
22
36
  - Gemfile
23
37
  - LICENSE.txt
24
38
  - README.md
@@ -26,6 +40,7 @@ files:
26
40
  - dedent.gemspec
27
41
  - lib/dedent.rb
28
42
  - lib/dedent/version.rb
43
+ - test/dedent_test.rb
29
44
  homepage: https://github.com/cespare/ruby-dedent
30
45
  licenses:
31
46
  - MIT
@@ -36,17 +51,17 @@ require_paths:
36
51
  - lib
37
52
  required_ruby_version: !ruby/object:Gem::Requirement
38
53
  requirements:
39
- - - '>='
54
+ - - ">="
40
55
  - !ruby/object:Gem::Version
41
56
  version: '0'
42
57
  required_rubygems_version: !ruby/object:Gem::Requirement
43
58
  requirements:
44
- - - '>='
59
+ - - ">="
45
60
  - !ruby/object:Gem::Version
46
61
  version: '0'
47
62
  requirements: []
48
63
  rubyforge_project: dedent
49
- rubygems_version: 2.0.3
64
+ rubygems_version: 2.2.2
50
65
  signing_key:
51
66
  specification_version: 4
52
67
  summary: Adds a dedent method to String.