ds_string 0.0.2
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 +15 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +5 -0
- data/Rakefile +29 -0
- data/lib/ds_string/core_ext.rb +48 -0
- data/lib/ds_string/version.rb +3 -0
- data/lib/ds_string.rb +3 -0
- data/spec/ds_string_spec.rb +33 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjdjNGQ1OTQ4MGY5ZDQ2M2YxZjFhMmM5ZTRhMDk2MmFhYmVhN2FmYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjgzNzRjYTQ5YzllZTc1YTAwYjAzNWQ2YzFhMzZiN2U4Y2MxMmZiYw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjljNmNjYmEyYmE1YjNjMTIxNzAwYThlOTIzN2IzOWNiNTg2ODRjY2M5MzRh
|
10
|
+
MDg5N2M1MDdmNWUyNGZlYzJhNmYxMTI0NzE3ZjhmZWNmMDRhNmUwOTAxOWYy
|
11
|
+
YTcxZWI0ZTMzMTE0ZjNhZjBlZDM0OTdlODU5OGExYmE0ZjRhZmI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGJhODg4MTJhZDE1YmU3ZjMyMzA1MjkwNGY2N2I1M2NhOGZkZTg4MzdhODhm
|
14
|
+
MTA0M2QxMGMwNmNlNWYxOTk0MGJmMmJkNDY4Yjg5NTk5NTM1MWNjNjM0NWY3
|
15
|
+
YzM4MDBjMTlmNTRiNzhhMDIxNjZmODNmOGEwNDBjNzgyODBjNTE=
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'DsString'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
Bundler::GemHelper.install_tasks
|
24
|
+
|
25
|
+
require 'rspec/core/rake_task'
|
26
|
+
|
27
|
+
RSpec::Core::RakeTask.new(:spec)
|
28
|
+
|
29
|
+
task :default => :spec
|
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
class String
|
3
|
+
|
4
|
+
def to_underscore
|
5
|
+
self.gsub!(/(.)([A-Z])/,'\1_\2').downcase!
|
6
|
+
end
|
7
|
+
|
8
|
+
# Extending a String class with a method to convert a string in a boolean value.
|
9
|
+
# Possibles case insensitive values are 'Yes','Y', 'No', 'N', '1', '0', 'true', 'false'
|
10
|
+
# "1".to_bool == true
|
11
|
+
# "y".to_bool == true
|
12
|
+
# "No".to_bool == true
|
13
|
+
def to_bool
|
14
|
+
return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
|
15
|
+
return false if self == false || self == '' || self == nil || self =~ (/(false|f|no|n|0)$/i)
|
16
|
+
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
|
17
|
+
end
|
18
|
+
|
19
|
+
# Extending a String class with method that repeat the string _n_ times.
|
20
|
+
# *simple case:*
|
21
|
+
# "a".times 2
|
22
|
+
# => "aa"
|
23
|
+
#
|
24
|
+
# *complex case:*
|
25
|
+
# j = 0
|
26
|
+
# 'A'.times 3 do |original_str, accumulative_str|
|
27
|
+
# j += 1
|
28
|
+
# "#{original_str}#{j}. "
|
29
|
+
# end
|
30
|
+
# => 'A1. A2. A3. '
|
31
|
+
def times num
|
32
|
+
ret = ''
|
33
|
+
num.times do
|
34
|
+
if block_given?
|
35
|
+
tmp = ret if ret != ''
|
36
|
+
ret += yield(self, tmp)
|
37
|
+
else
|
38
|
+
ret += self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
ret
|
42
|
+
end
|
43
|
+
|
44
|
+
def for_debug
|
45
|
+
"\n#{'+'.times 8}>\n#{self}#{'-'.times 8}>\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/lib/ds_string.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'ds_string'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
|
5
|
+
context "#times" do
|
6
|
+
it { "0".times(3).should eq "000"}
|
7
|
+
it { "0".times 3 do |s| "#{s}A,"; end.should eq "0A,0A,0A,"}
|
8
|
+
it { "A".times 3 do |s,c| "#{c||s}X-"; end.should eq "AX-AX-X-AX-AX-X-X-"}
|
9
|
+
end
|
10
|
+
|
11
|
+
context "#to_bool" do
|
12
|
+
|
13
|
+
it { "1".to_bool.should be_true }
|
14
|
+
it { "y".to_bool.should be_true }
|
15
|
+
it { "yes".to_bool.should be_true }
|
16
|
+
it { "t".to_bool.should be_true }
|
17
|
+
it { "true".to_bool.should be_true }
|
18
|
+
it { "True".to_bool.should be_true }
|
19
|
+
it { "TRUE".to_bool.should be_true }
|
20
|
+
|
21
|
+
it { "0".to_bool.should be_false }
|
22
|
+
it { "n".to_bool.should be_false }
|
23
|
+
it { "no".to_bool.should be_false }
|
24
|
+
it { "f".to_bool.should be_false }
|
25
|
+
it { "false".to_bool.should be_false }
|
26
|
+
it { "False".to_bool.should be_false }
|
27
|
+
it { "FALSE".to_bool.should be_false }
|
28
|
+
|
29
|
+
it { expect{ "xx".to_bool }.to raise_error }
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ds_string
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nardele Salomon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: String extensions
|
14
|
+
email:
|
15
|
+
- del.soft.99@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/ds_string.rb
|
21
|
+
- lib/ds_string/version.rb
|
22
|
+
- lib/ds_string/core_ext.rb
|
23
|
+
- MIT-LICENSE
|
24
|
+
- Rakefile
|
25
|
+
- README.rdoc
|
26
|
+
- spec/ds_string_spec.rb
|
27
|
+
homepage: https://github.com/delsoft
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.0.3
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: String extensions 0.0.2
|
51
|
+
test_files:
|
52
|
+
- spec/ds_string_spec.rb
|