powerpack 0.0.2 → 0.0.3

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: 4b1dee25575ff6e8b6dc5b84b6a6a2f000389e00
4
- data.tar.gz: 4eed3f28b561507e70a1828a6fcc74cf6e8a4c22
3
+ metadata.gz: b5ae47f06545fa305812faece61d4a22a32f29cf
4
+ data.tar.gz: ffc7a033f26e64169194bd31fd0e0d3a97ddb145
5
5
  SHA512:
6
- metadata.gz: 41e393fc5b3b067fd7551533d13c128f5357387485417812eaa318c3f96feea99f5ee15318d7e74e633540adc07dbf944d3d4a9af78274c18250cf83cc4e4541
7
- data.tar.gz: a68471ecde73ac4a51273971bf936c7621950d3e27d8ced65786153397d9f7104236e2f1840d63c93d429e71fd58e9041f8419826a57f6e61872ad3b59b4e7e6
6
+ metadata.gz: ea7099ee760815ad0b5257690a2cc48925c677956f7b51f9a974fe1d19f31b3cd4fcadd9b6ac09b7f57815923d71774ccca763a234785ed34495c48377d8609a
7
+ data.tar.gz: 298cd5779cd56510d5089f85c23b8cc7b74920cd0be906682c6b214af047c7786d72f4410dc0c017f9931bc2137b17096ebb1222b16d548790b89f2a21997431
data/README.md CHANGED
@@ -22,12 +22,13 @@ Or install it yourself as:
22
22
  ## Extensions
23
23
 
24
24
  * [Hash](http://rdoc.info/github/bbatsov/powerpack/Hash)
25
- ** [#symbolize_keys](http://rdoc.info/github/bbatsov/powerpack/Hash#symbolize_keys-instance_method)
25
+ * [#symbolize_keys](http://rdoc.info/github/bbatsov/powerpack/Hash#symbolize_keys-instance_method)
26
26
  * [String](http://rdoc.info/github/bbatsov/powerpack/String)
27
- ** [#blank?](http://rdoc.info/github/bbatsov/powerpack/String#blank?-instance_method)
28
- ** [#format](http://rdoc.info/github/bbatsov/powerpack/String#format-instance_method)
29
- ** [#strip_indent](http://rdoc.info/github/bbatsov/powerpack/String#strip_indent-instance_method)
30
- ** [#strip_margin](http://rdoc.info/github/bbatsov/powerpack/String#strip_margin-instance_method)
27
+ * [#blank?](http://rdoc.info/github/bbatsov/powerpack/String#blank?-instance_method)
28
+ * [#format](http://rdoc.info/github/bbatsov/powerpack/String#format-instance_method)
29
+ * [#strip_indent](http://rdoc.info/github/bbatsov/powerpack/String#strip_indent-instance_method)
30
+ * [#strip_margin](http://rdoc.info/github/bbatsov/powerpack/String#strip_margin-instance_method)
31
+ * [#squish](http://rdoc.info/github/bbatsov/powerpack/String#squish-instance_method)
31
32
 
32
33
  ## Documentation
33
34
 
@@ -1,7 +1,11 @@
1
1
  unless Hash.method_defined? :symbolize_keys
2
2
  class Hash
3
- # The method behaves like turns the keys of the hash to symbols.
4
- # It returns a copy of the original hash.
3
+ # Converts the keys of the hash to symbols.
4
+ #
5
+ # @return [Hash] a copy of the original hash with its keys converted to symbols.
6
+ #
7
+ # @example
8
+ # { 'one' => 1, 'two' => 2 }.symbolize_keys #=> { :one => 1, :two => 2 }
5
9
  def symbolize_keys
6
10
  Hash[map { |(k, v)| [k.to_sym, v] }]
7
11
  end
@@ -2,3 +2,4 @@ require_relative 'string/blank'
2
2
  require_relative 'string/format'
3
3
  require_relative 'string/strip_indent'
4
4
  require_relative 'string/strip_margin'
5
+ require_relative 'string/squish'
@@ -1,9 +1,20 @@
1
1
  unless String.method_defined? :blank?
2
2
  class String
3
- # Returns true for empty strings and string with
4
- # only whitespace in them.
3
+ # Checks whether a string is blank.
4
+ #
5
+ # @return [String] `true` is the string is empty or contains only
6
+ # whitespace, `false` otherwise
7
+ #
8
+ # @example
9
+ # ''.blank? #=> true
10
+ #
11
+ # @example
12
+ # ' '.blank? #=> true
13
+ #
14
+ # @example
15
+ # ' test'.blank? #=> false
5
16
  def blank?
6
- self.empty? || self.strip.empty?
17
+ empty? || strip.empty?
7
18
  end
8
19
  end
9
20
  end
@@ -1,6 +1,14 @@
1
1
  unless String.method_defined? :format
2
2
  class String
3
- # The method behaves like `Kernel#sprintf` and `String#%`.
3
+ # A nicer alternative to `Kernel#sprintf` and `String#%`.
4
+ #
5
+ # @return [String] the formatted string
6
+ #
7
+ # @example
8
+ # 'This is %s!'.format('Sparta') #=> 'This is Sparta!'
9
+ #
10
+ # @example
11
+ # '%d + %d'.format([1, 2]) #=> '1 + 2'
4
12
  def format(*args)
5
13
  super(self, *(args.flatten(1)))
6
14
  end
@@ -0,0 +1,14 @@
1
+ unless String.method_defined? :squish
2
+ class String
3
+ # Strips leading and trailing whitespace and squashes internal whitespace.
4
+ #
5
+ # @return [String] a string with not leading and traling whitespace and no
6
+ # consecutive whitespace characters inside it
7
+ #
8
+ # @example
9
+ # ' Peter Parker'.squish #=> 'Peter Parker'
10
+ def squish
11
+ strip.gsub(/\s+/, ' ')
12
+ end
13
+ end
14
+ end
@@ -5,14 +5,14 @@ unless String.method_defined? :strip_indent
5
5
  #
6
6
  # @example
7
7
  #
8
- # code = <<-END.strip_indent
9
- # def test
10
- # some_method
11
- # other_method
12
- # end
13
- # END
8
+ # code = <<-END.strip_indent
9
+ # def test
10
+ # some_method
11
+ # other_method
12
+ # end
13
+ # END
14
14
  #
15
- # => "def\n some_method\n \nother_method\nend"
15
+ # #=> "def\n some_method\n \nother_method\nend"
16
16
  def strip_indent
17
17
  leading_space = scan(/^[ \t]*(?=\S)/).min
18
18
  indent = leading_space ? leading_space.size : 0
@@ -5,14 +5,14 @@ unless String.method_defined? :strip_margin
5
5
  #
6
6
  # @example
7
7
  #
8
- # code = <<-END.strip_margin('|')
9
- # |def test
10
- # | some_method
11
- # | other_method
12
- # |end
13
- # END
8
+ # code = <<-END.strip_margin('|')
9
+ # |def test
10
+ # | some_method
11
+ # | other_method
12
+ # |end
13
+ # END
14
14
  #
15
- # => "def\n some_method\n \nother_method\nend"
15
+ # #=> "def\n some_method\n \nother_method\nend"
16
16
  def strip_margin(margin_character)
17
17
  margin = '\\' + margin_character
18
18
  gsub(/^\s+#{margin}/, '')
@@ -1,3 +1,3 @@
1
1
  module Powerpack
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'String#squish' do
4
+ it 'strips leading and trailing whitespace' do
5
+ expect(' Peter '.squish).to eq('Peter')
6
+ end
7
+
8
+ it 'compacts internal whitespace' do
9
+ expect("Peter\r\n \t Parker".squish).to eq('Peter Parker')
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: powerpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -86,6 +86,7 @@ files:
86
86
  - lib/powerpack/string.rb
87
87
  - lib/powerpack/string/blank.rb
88
88
  - lib/powerpack/string/format.rb
89
+ - lib/powerpack/string/squish.rb
89
90
  - lib/powerpack/string/strip_indent.rb
90
91
  - lib/powerpack/string/strip_margin.rb
91
92
  - lib/powerpack/version.rb
@@ -93,6 +94,7 @@ files:
93
94
  - spec/powerpack/hash/symbolize_keys_spec.rb
94
95
  - spec/powerpack/string/blank_spec.rb
95
96
  - spec/powerpack/string/format_spec.rb
97
+ - spec/powerpack/string/squish_spec.rb
96
98
  - spec/powerpack/string/strip_indent_spec.rb
97
99
  - spec/powerpack/string/strip_margin_spec.rb
98
100
  - spec/spec_helper.rb
@@ -124,6 +126,7 @@ test_files:
124
126
  - spec/powerpack/hash/symbolize_keys_spec.rb
125
127
  - spec/powerpack/string/blank_spec.rb
126
128
  - spec/powerpack/string/format_spec.rb
129
+ - spec/powerpack/string/squish_spec.rb
127
130
  - spec/powerpack/string/strip_indent_spec.rb
128
131
  - spec/powerpack/string/strip_margin_spec.rb
129
132
  - spec/spec_helper.rb