powerpack 0.0.3 → 0.0.4
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 +4 -4
- data/README.md +3 -0
- data/Rakefile +6 -1
- data/lib/powerpack.rb +2 -0
- data/lib/powerpack/hash/symbolize_keys.rb +1 -1
- data/lib/powerpack/numeric.rb +2 -0
- data/lib/powerpack/numeric/neg.rb +19 -0
- data/lib/powerpack/numeric/pos.rb +19 -0
- data/lib/powerpack/string/blank.rb +3 -3
- data/lib/powerpack/string/format.rb +1 -1
- data/lib/powerpack/string/squish.rb +2 -2
- data/lib/powerpack/version.rb +1 -1
- data/spec/powerpack/numeric/neg_spec.rb +24 -0
- data/spec/powerpack/numeric/pos_spec.rb +24 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d33e4476c5faccdafe8e8065366f11e4a65478e7
|
4
|
+
data.tar.gz: 5c592ba39bcd2d5e57210e17e27138d245e4420e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7d594c9deaabc166e4f9030c7f2efd13d9598d810b3abe784b1ed63a673a3fc9c7da18a2c60f75aa0e3b5a1ea4f8d70bedfa3464a361b4b887239d4933d7e71
|
7
|
+
data.tar.gz: d0c5b207e0111a33ad38d64551561b0dc65f7330246924119185348479bfdbe5d6cc31cd64d7a8adf9a35a3658dbafbe99573c06b4fe73d93ba84dbb50cadf2f
|
data/README.md
CHANGED
@@ -23,6 +23,9 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
* [Hash](http://rdoc.info/github/bbatsov/powerpack/Hash)
|
25
25
|
* [#symbolize_keys](http://rdoc.info/github/bbatsov/powerpack/Hash#symbolize_keys-instance_method)
|
26
|
+
* [Numeric](http://rdoc.info/github/bbatsov/powerpack/Numeric)
|
27
|
+
* [#pos?](http://rdoc.info/github/bbatsov/powerpack/Numeric#pos?-instance_method)
|
28
|
+
* [#neg?](http://rdoc.info/github/bbatsov/powerpack/Numeric#neg?-instance_method)
|
26
29
|
* [String](http://rdoc.info/github/bbatsov/powerpack/String)
|
27
30
|
* [#blank?](http://rdoc.info/github/bbatsov/powerpack/String#blank?-instance_method)
|
28
31
|
* [#format](http://rdoc.info/github/bbatsov/powerpack/String#format-instance_method)
|
data/Rakefile
CHANGED
data/lib/powerpack.rb
CHANGED
@@ -2,7 +2,7 @@ unless Hash.method_defined? :symbolize_keys
|
|
2
2
|
class Hash
|
3
3
|
# Converts the keys of the hash to symbols.
|
4
4
|
#
|
5
|
-
# @return [Hash] a copy of the original hash with its keys converted to symbols
|
5
|
+
# @return [Hash] a copy of the original hash with its keys converted to symbols
|
6
6
|
#
|
7
7
|
# @example
|
8
8
|
# { 'one' => 1, 'two' => 2 }.symbolize_keys #=> { :one => 1, :two => 2 }
|
@@ -0,0 +1,19 @@
|
|
1
|
+
unless Numeric.method_defined? :neg?
|
2
|
+
class Numeric
|
3
|
+
# Checks whether a number is negative.
|
4
|
+
#
|
5
|
+
# @return [Boolean] true is the number is negative, false otherwise
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# 5.neg? #=> false
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# -0.5.neg? #=> true
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# 0.neg? #=> false
|
15
|
+
def neg?
|
16
|
+
self < 0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
unless Numeric.method_defined? :pos?
|
2
|
+
class Numeric
|
3
|
+
# Checks whether a number is positive.
|
4
|
+
#
|
5
|
+
# @return [Boolean] true is the number is positive, false otherwise
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# 5.pos? #=> true
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# -0.5.pos? #=> false
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# 0.pos? #=> false
|
15
|
+
def pos?
|
16
|
+
self > 0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
unless String.method_defined? :blank?
|
2
2
|
class String
|
3
|
-
# Checks whether a string is blank.
|
3
|
+
# Checks whether a string is blank. A string is considered blank if it
|
4
|
+
# is either empty or contains only whitespace characters.
|
4
5
|
#
|
5
|
-
# @return [
|
6
|
-
# whitespace, `false` otherwise
|
6
|
+
# @return [Boolean] true is the string is blank, false otherwise
|
7
7
|
#
|
8
8
|
# @example
|
9
9
|
# ''.blank? #=> true
|
@@ -2,8 +2,8 @@ unless String.method_defined? :squish
|
|
2
2
|
class String
|
3
3
|
# Strips leading and trailing whitespace and squashes internal whitespace.
|
4
4
|
#
|
5
|
-
# @return [String] a string with
|
6
|
-
#
|
5
|
+
# @return [String] a string with no leading and traling whitespace and no
|
6
|
+
# consecutive whitespace characters inside it
|
7
7
|
#
|
8
8
|
# @example
|
9
9
|
# ' Peter Parker'.squish #=> 'Peter Parker'
|
data/lib/powerpack/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Numeric#neg?' do
|
4
|
+
it 'returns false for positive integer' do
|
5
|
+
expect(1.neg?).to be_false
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'returns false for positive float' do
|
9
|
+
expect(0.1.neg?).to be_false
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns true for negative integer' do
|
13
|
+
expect(-1.neg?).to be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns true for negative float' do
|
17
|
+
expect(-0.01.neg?).to be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns false for 0' do
|
21
|
+
expect(0.neg?).to be_false
|
22
|
+
expect(0.0.neg?).to be_false
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Numeric#pos?' do
|
4
|
+
it 'returns true for positive integer' do
|
5
|
+
expect(1.pos?).to be_true
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'returns true for positive float' do
|
9
|
+
expect(0.1.pos?).to be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns false for negative integer' do
|
13
|
+
expect(-1.pos?).to be_false
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns false for negative float' do
|
17
|
+
expect(-0.01.pos?).to be_false
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns false for 0' do
|
21
|
+
expect(0.pos?).to be_false
|
22
|
+
expect(0.0.pos?).to be_false
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: powerpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,6 +83,9 @@ files:
|
|
83
83
|
- lib/powerpack.rb
|
84
84
|
- lib/powerpack/hash.rb
|
85
85
|
- lib/powerpack/hash/symbolize_keys.rb
|
86
|
+
- lib/powerpack/numeric.rb
|
87
|
+
- lib/powerpack/numeric/neg.rb
|
88
|
+
- lib/powerpack/numeric/pos.rb
|
86
89
|
- lib/powerpack/string.rb
|
87
90
|
- lib/powerpack/string/blank.rb
|
88
91
|
- lib/powerpack/string/format.rb
|
@@ -92,6 +95,8 @@ files:
|
|
92
95
|
- lib/powerpack/version.rb
|
93
96
|
- powerpack.gemspec
|
94
97
|
- spec/powerpack/hash/symbolize_keys_spec.rb
|
98
|
+
- spec/powerpack/numeric/neg_spec.rb
|
99
|
+
- spec/powerpack/numeric/pos_spec.rb
|
95
100
|
- spec/powerpack/string/blank_spec.rb
|
96
101
|
- spec/powerpack/string/format_spec.rb
|
97
102
|
- spec/powerpack/string/squish_spec.rb
|
@@ -124,6 +129,8 @@ specification_version: 4
|
|
124
129
|
summary: A few useful extensions to core Ruby classes.
|
125
130
|
test_files:
|
126
131
|
- spec/powerpack/hash/symbolize_keys_spec.rb
|
132
|
+
- spec/powerpack/numeric/neg_spec.rb
|
133
|
+
- spec/powerpack/numeric/pos_spec.rb
|
127
134
|
- spec/powerpack/string/blank_spec.rb
|
128
135
|
- spec/powerpack/string/format_spec.rb
|
129
136
|
- spec/powerpack/string/squish_spec.rb
|