gemsupport 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48d74caf4b4620757a8dc7f06697a66e49c1b16c
4
- data.tar.gz: 6566dc240c31fe3fe23afc79c85df84ef244fee8
3
+ metadata.gz: b3df4c71cd4f48bf0665a2a0c307d4b595e0e756
4
+ data.tar.gz: 867518858d56bef29f40fb3e420f1b32d771ac2a
5
5
  SHA512:
6
- metadata.gz: 23b1f2fb787800dfea17a0ab9ac673b5c2ccf86b36becd10834caebe3ad63ccb46684718c70f6957fb9fc0ce9efd29fa42e20956e526e42a4f79c205bbf9b24e
7
- data.tar.gz: 2335126661a157bc5cd5aa4337279cb6abb941b2fdf5a50ece9631b78bb65a354717eefa5d2d052da9ff75747231f1108bd2bc69857dcadf1e9a194f1497dc63
6
+ metadata.gz: 29ac3ab4616a0be74e0be945cd58d01146e5f53e5301d213a0158f1f8694fc2513bebb49888ad1cecdd7c100f33d9a88ce49a43ef7937b612096a1b4b8438422
7
+ data.tar.gz: d5972738e8e21d41b92929d849a7ccdcc778176d940031334a98bfd6d49d65f3fb0eb884de4f665e0e504e777a75e8143e81074137cdfb09cf63a8a7716a0a33
@@ -13,4 +13,19 @@ String.class_eval do
13
13
  e.split('_').map { |w| w.capitalize }.join
14
14
  end.join('::')
15
15
  end
16
+
17
+ # Remove indentation spaces for multilines string
18
+ # From:
19
+ # | Anonymous Coward
20
+ # | - Community Guest
21
+ # To:
22
+ # |Anonymous Coward
23
+ # | - Community Guest
24
+ def unindent
25
+ gsub(/^#{scan(/^[ \t]+(?=\S)/).min}/, '')
26
+ end
27
+
28
+ def unindent!
29
+ replace(unindent)
30
+ end
16
31
  end
@@ -1,3 +1,3 @@
1
1
  module Gemsupport
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -58,4 +58,47 @@ describe 'String' do
58
58
  end
59
59
  end
60
60
  end
61
+
62
+ describe '#unindent' do
63
+ context 'when empty string' do
64
+ it 'does not remove anything' do
65
+ expect(''.unindent).to eq('')
66
+ end
67
+ end
68
+
69
+ context 'When simple line indentation' do
70
+ it 'removes the spaces' do
71
+ expect("\s\sabc".unindent).to eq('abc')
72
+ end
73
+
74
+ it 'removes the tabs' do
75
+ expect("\tabc".unindent).to eq('abc')
76
+ end
77
+
78
+ it 'removes the whintespaces' do
79
+ expect("\t\s\sabc".unindent).to eq('abc')
80
+ end
81
+ end
82
+
83
+ context 'when multi-line identation' do
84
+ it 'removes the whitespaces' do
85
+ expect("\t\sabc\n\t\sabc".unindent).to eq("abc\nabc")
86
+ end
87
+
88
+ it 'keeps relative indentation' do
89
+ expect("\tabc\n\t\tabc".unindent).to eq("abc\n\tabc")
90
+ end
91
+
92
+ it 'ignores blank lines for indent calculation' do
93
+ expect("\n\tabc\n\n\t\tabc\n".unindent).to eq("\nabc\n\n\tabc\n")
94
+ end
95
+ end
96
+ end
97
+
98
+ describe '#unindent!' do
99
+ let(:source) { "\s\sabc" }
100
+ it 'modifies string in place' do
101
+ expect { source.unindent! }.to change { source }.from("\s\sabc").to('abc')
102
+ end
103
+ end
61
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemsupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mdouchement
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler