powerpack 0.0.8 → 0.0.9
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/CHANGELOG.md +7 -0
- data/README.md +4 -0
- data/lib/powerpack/enumerable/exactly.rb +2 -0
- data/lib/powerpack/string.rb +2 -0
- data/lib/powerpack/string/ascii_only.rb +42 -0
- data/lib/powerpack/string/remove.rb +17 -0
- data/lib/powerpack/version.rb +1 -1
- data/spec/powerpack/string/ascii_only_spec.rb +45 -0
- data/spec/powerpack/string/remove_spec.rb +13 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d3df53a4979884a29c563336460368f50c8235b
|
4
|
+
data.tar.gz: 0b4f51bcf7c5374cd5ebb4d48543c7450461796f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2006ba07ffea976d3cbdc95dbf6cd88de0f69551ea8b95bf32e8ad196f3d29806284cd94aced250a71f72f4a7289410489f74dae2cad748f0c72298ea504db9a
|
7
|
+
data.tar.gz: 8bf8a78aeb5967a9ecedc1a261f7d92cb73c08f81f9ff1c5985ad579d8b1199a6c1720608e56551b4b7067666ab3554dbb5c1e5375c8ce54b4c836028dd27369
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -46,8 +46,12 @@ Or install it yourself as:
|
|
46
46
|
* [#trillion](http://rdoc.info/github/bbatsov/powerpack/Numeric#trillion-instance_method)
|
47
47
|
* [#quadrillion](http://rdoc.info/github/bbatsov/powerpack/Numeric#quadrillion-instance_method)
|
48
48
|
* [String](http://rdoc.info/github/bbatsov/powerpack/String)
|
49
|
+
* [#ascii_only](http://rdoc.info/github/bbatsov/powerpack/String#ascii_only-instance_method)
|
50
|
+
* [#ascii_only!](http://rdoc.info/github/bbatsov/powerpack/String#ascii_only!-instance_method)
|
49
51
|
* [#blank?](http://rdoc.info/github/bbatsov/powerpack/String#blank?-instance_method)
|
50
52
|
* [#format](http://rdoc.info/github/bbatsov/powerpack/String#format-instance_method)
|
53
|
+
* [#remove](http://rdoc.info/github/bbatsov/powerpack/String#remove-instance_method)
|
54
|
+
* [#remove!](http://rdoc.info/github/bbatsov/powerpack/String#remove!-instance_method)
|
51
55
|
* [#strip_indent](http://rdoc.info/github/bbatsov/powerpack/String#strip_indent-instance_method)
|
52
56
|
* [#strip_margin](http://rdoc.info/github/bbatsov/powerpack/String#strip_margin-instance_method)
|
53
57
|
* [#squish](http://rdoc.info/github/bbatsov/powerpack/String#squish-instance_method)
|
@@ -25,12 +25,14 @@ unless Enumerable.method_defined? :exactly?
|
|
25
25
|
each do |*o|
|
26
26
|
if yield(*o)
|
27
27
|
found_count += 1
|
28
|
+
return false if found_count > n
|
28
29
|
end
|
29
30
|
end
|
30
31
|
else
|
31
32
|
each do |o|
|
32
33
|
if o
|
33
34
|
found_count += 1
|
35
|
+
return false if found_count > n
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
data/lib/powerpack/string.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class String
|
4
|
+
# Return a copy of string with ASCII characters only
|
5
|
+
# Source: http://stackoverflow.com/questions/1268289/how-to-get-rid-of-non-ascii-characters-in-ruby
|
6
|
+
#
|
7
|
+
# @return [String] a copy of string with ASCII characters only
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# 'abc'.ascii_only #=> 'abc'
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# '中文123'.ascii_only #=> '123'
|
14
|
+
unless String.method_defined? :ascii_only
|
15
|
+
def ascii_only
|
16
|
+
dup.ascii_only!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Modify self and keep ASCII characters only
|
21
|
+
# Returns the string even if no changes were made.
|
22
|
+
# Source: http://stackoverflow.com/questions/1268289/how-to-get-rid-of-non-ascii-characters-in-ruby
|
23
|
+
#
|
24
|
+
# @return [String] The result string
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# 'abc'.ascii_only! #=> 'abc'
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# '中文123'.ascii_only! #=> '123'
|
31
|
+
unless String.method_defined? :ascii_only!
|
32
|
+
def ascii_only!
|
33
|
+
encoding_options = {
|
34
|
+
:invalid => :replace, # Replace invalid byte sequences
|
35
|
+
:undef => :replace, # Replace anything not defined in ASCII
|
36
|
+
:replace => '', # Use a blank for those replacements
|
37
|
+
:UNIVERSAL_NEWLINE_DECORATOR => true # Always break lines with \n
|
38
|
+
}
|
39
|
+
self.encode! Encoding.find('ASCII'), encoding_options
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
unless String.method_defined? :remove
|
2
|
+
class String
|
3
|
+
# Removes all occurrences of a pattern in a string.
|
4
|
+
#
|
5
|
+
# @return [String] a new string without any occurrences of the pattern.
|
6
|
+
def remove(pattern)
|
7
|
+
dup.remove!(pattern)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Removes all occurrences of a pattern in a string.
|
11
|
+
#
|
12
|
+
# @return [String] the string without any occurrences of the pattern.
|
13
|
+
def remove!(pattern)
|
14
|
+
gsub!(pattern, '')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/powerpack/version.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
6
|
+
describe 'String#ascii_only' do
|
7
|
+
it 'returns same value for string with ASCII chars only' do
|
8
|
+
expect('abc'.ascii_only).to eq 'abc'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns string without non-ASCII chars' do
|
12
|
+
expect("abc\u{6666}".force_encoding("UTF-8").ascii_only).to eq 'abc'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns string without non-ASCII chars and with ASCII chars' do
|
16
|
+
expect("\u{6666}".force_encoding("UTF-8").ascii_only).to eq ''
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'does not change the original string' do
|
20
|
+
string = "abc\u{6666}".force_encoding("UTF-8")
|
21
|
+
string.ascii_only
|
22
|
+
expect(string).to eq "abc\u{6666}".force_encoding("UTF-8")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'String#ascii_only!' do
|
27
|
+
it 'returns same value for string with ASCII chars only' do
|
28
|
+
expect('abc'.ascii_only!).to eq 'abc'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns string without non-ASCII chars' do
|
32
|
+
expect("abc\u{6666}".force_encoding("UTF-8").ascii_only!).to eq 'abc'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns string without non-ASCII chars and with ASCII chars' do
|
36
|
+
expect("\u{6666}".force_encoding("UTF-8").ascii_only!).to eq ''
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'changes the original string' do
|
40
|
+
string = "abc\u{6666}".force_encoding("UTF-8")
|
41
|
+
string.ascii_only!
|
42
|
+
expect(string).to eq 'abc'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'String#remove' do
|
4
|
+
it 'removes all occurrences of a pattern' do
|
5
|
+
expect('Ladies Night'.remove(/Ladies /)).to eq('Night')
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'String#remove!' do
|
10
|
+
it 'removes all occurrences of a pattern' do
|
11
|
+
expect('Ladies Night'.remove(/Ladies /)).to eq('Night')
|
12
|
+
end
|
13
|
+
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.9
|
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-
|
11
|
+
date: 2013-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,8 +102,10 @@ files:
|
|
102
102
|
- lib/powerpack/numeric/pos.rb
|
103
103
|
- lib/powerpack/numeric/scale.rb
|
104
104
|
- lib/powerpack/string.rb
|
105
|
+
- lib/powerpack/string/ascii_only.rb
|
105
106
|
- lib/powerpack/string/blank.rb
|
106
107
|
- lib/powerpack/string/format.rb
|
108
|
+
- lib/powerpack/string/remove.rb
|
107
109
|
- lib/powerpack/string/squish.rb
|
108
110
|
- lib/powerpack/string/strip_indent.rb
|
109
111
|
- lib/powerpack/string/strip_margin.rb
|
@@ -124,8 +126,10 @@ files:
|
|
124
126
|
- spec/powerpack/numeric/neg_spec.rb
|
125
127
|
- spec/powerpack/numeric/pos_spec.rb
|
126
128
|
- spec/powerpack/numeric/scale_spec.rb
|
129
|
+
- spec/powerpack/string/ascii_only_spec.rb
|
127
130
|
- spec/powerpack/string/blank_spec.rb
|
128
131
|
- spec/powerpack/string/format_spec.rb
|
132
|
+
- spec/powerpack/string/remove_spec.rb
|
129
133
|
- spec/powerpack/string/squish_spec.rb
|
130
134
|
- spec/powerpack/string/strip_indent_spec.rb
|
131
135
|
- spec/powerpack/string/strip_margin_spec.rb
|
@@ -170,8 +174,10 @@ test_files:
|
|
170
174
|
- spec/powerpack/numeric/neg_spec.rb
|
171
175
|
- spec/powerpack/numeric/pos_spec.rb
|
172
176
|
- spec/powerpack/numeric/scale_spec.rb
|
177
|
+
- spec/powerpack/string/ascii_only_spec.rb
|
173
178
|
- spec/powerpack/string/blank_spec.rb
|
174
179
|
- spec/powerpack/string/format_spec.rb
|
180
|
+
- spec/powerpack/string/remove_spec.rb
|
175
181
|
- spec/powerpack/string/squish_spec.rb
|
176
182
|
- spec/powerpack/string/strip_indent_spec.rb
|
177
183
|
- spec/powerpack/string/strip_margin_spec.rb
|