string_plus 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19675b7d45763d2af2b26354da6f1cf9c4791810
4
- data.tar.gz: e6cc5bb38954ca0099837abeada9faba716c7242
3
+ metadata.gz: 8ca9e13243b9c565286047667ecccf090fba5733
4
+ data.tar.gz: af81e5466f9f38e83a234fd08750f45bdb2ffd3a
5
5
  SHA512:
6
- metadata.gz: 1798989d1c67b0072add28f3eae074beff7c5a93ffbc33479d9dbd7bf2232ff9455f34b84f23f12a64b34bfc0d9ad33ddaa77202bf3def2dea88bb3880f28c27
7
- data.tar.gz: cfaa69ea50b533981bfb4255259367050944347b33143acf7f2b09ceabdb29ac26f9deef05114d1c541511f99ec62d1731323b7c3c66fed9a2ed3576f8d92fcd
6
+ metadata.gz: 0bba3cff8accd05c32d67a3731dfdae0afdef42a6e80236b6602c1d882d01f49142d6b61ffaad55554b547b2d49b1c537442818b6bd436d205175fa66906e3a3
7
+ data.tar.gz: bb70d6d2d809856f245b2d47222b564e83000170c68b96a982c68f7a67fa61ac400d9e108d3bd39b32c2d6b4df8849ab6a70e317fc7f55ec1bf83a190f0a0cb5
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
+ gemspec
2
3
 
3
- # Specify your gem's dependencies in string_plus.gemspec
4
- gemspec
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
1
  require "bundler/gem_tasks"
2
-
2
+ require "matest/spec_tasks"
data/lib/string_plus.rb CHANGED
@@ -5,7 +5,7 @@ module StringPlus
5
5
  res = ""
6
6
  flag = capitalize_first_char
7
7
  self.each_char {|w|
8
- (flag = true ; next) if w == "_"
8
+ (flag = true ; next) if w == "_" || w == " "
9
9
  res << if flag
10
10
  flag = false
11
11
  w.upcase
@@ -16,9 +16,10 @@ module StringPlus
16
16
  res
17
17
  end
18
18
 
19
- def snakecase
19
+ def lcamelcase
20
20
  camelcase(false)
21
21
  end
22
+
22
23
  end
23
24
 
24
25
  String.send(:include, StringPlus)
@@ -0,0 +1,25 @@
1
+ require "benchmark"
2
+ require "string_plus"
3
+ str = "federico_martin_iachetti"
4
+
5
+ [ 1, 10, 100, 1_000, 10_000, 100_000, 1_000_000].each do |n|
6
+ puts ">>>>> n: #{n}"
7
+
8
+ Benchmark.bm(20) do |x|
9
+ x.report("split map:") {
10
+ 1.upto(n) do
11
+ str.split("_").map(&:capitalize).join
12
+ end
13
+ }
14
+ x.report("gsub:") {
15
+ 1.upto(n) do
16
+ str.gsub(/[a-zA-Z0-9]+/, &:capitalize).gsub("_", "")
17
+ end
18
+ }
19
+ x.report("camelcase:") {
20
+ str.camelcase
21
+ }
22
+ end
23
+ puts
24
+ end
25
+
@@ -1,3 +1,3 @@
1
1
  module StringPlus
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,36 @@
1
+ require "benchmark"
2
+ require "string_plus"
3
+ str = "federico_martin_iachetti"
4
+
5
+ [ 1, 10, 100, 1_000, 10_000, 100_000, 1_000_000].each do |n|
6
+ puts ">>>>> n: #{n}"
7
+ Benchmark.bm(20) do |x|
8
+ x.report("split map:") {
9
+ 1.upto(n) do
10
+ str.split("_").map(&:capitalize).join
11
+ end
12
+ }
13
+ x.report("gsub:") {
14
+ 1.upto(n) do
15
+ str.gsub(/[a-zA-Z0-9]+/, &:capitalize).gsub("_", "")
16
+ end
17
+ }
18
+ x.report("camelcase:") {
19
+ str.camelcase
20
+ }
21
+ end
22
+ end
23
+ # ~> -:18:in `block (3 levels) in <main>': undefined method `camelcase' for "federico_martin_iachetti":String (NoMethodError)
24
+ # ~> from /home/fedex/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/benchmark.rb:288:in `measure'
25
+ # ~> from /home/fedex/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/benchmark.rb:370:in `item'
26
+ # ~> from -:17:in `block (2 levels) in <main>'
27
+ # ~> from /home/fedex/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/benchmark.rb:172:in `benchmark'
28
+ # ~> from /home/fedex/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/benchmark.rb:204:in `bm'
29
+ # ~> from -:6:in `block in <main>'
30
+ # ~> from -:4:in `each'
31
+ # ~> from -:4:in `<main>'
32
+ # >> >>>>> n: 1
33
+ # >> user system total real
34
+ # >> split map: 0.000000 0.000000 0.000000 ( 0.000027)
35
+ # >> gsub: 0.000000 0.000000 0.000000 ( 0.000027)
36
+ # >> camelcase:
@@ -0,0 +1,57 @@
1
+ require "benchmark"
2
+ require "string_plus"
3
+ str = "federico_martin_iachetti"
4
+
5
+ [ 1, 10, 100, 1_000, 10_000, 100_000, 1_000_000].each do |n|
6
+ puts ">>>>> n: #{n}"
7
+ Benchmark.bm(20) do |x|
8
+ x.report("split map:") {
9
+ 1.upto(n) do
10
+ str.split("_").map(&:capitalize).join
11
+ end
12
+ }
13
+ x.report("gsub:") {
14
+ 1.upto(n) do
15
+ str.gsub(/[a-zA-Z0-9]+/, &:capitalize).gsub("_", "")
16
+ end
17
+ }
18
+ x.report("camelcase:") {
19
+ str.camelcase
20
+ }
21
+ end
22
+ end
23
+ # >> >>>>> n: 1
24
+ # >> user system total real
25
+ # >> split map: 0.000000 0.000000 0.000000 ( 0.000018)
26
+ # >> gsub: 0.000000 0.000000 0.000000 ( 0.000020)
27
+ # >> camelcase: 0.000000 0.000000 0.000000 ( 0.000013)
28
+ # >> >>>>> n: 10
29
+ # >> user system total real
30
+ # >> split map: 0.000000 0.000000 0.000000 ( 0.000040)
31
+ # >> gsub: 0.000000 0.000000 0.000000 ( 0.000064)
32
+ # >> camelcase: 0.000000 0.000000 0.000000 ( 0.000009)
33
+ # >> >>>>> n: 100
34
+ # >> user system total real
35
+ # >> split map: 0.000000 0.000000 0.000000 ( 0.000240)
36
+ # >> gsub: 0.000000 0.000000 0.000000 ( 0.000610)
37
+ # >> camelcase: 0.000000 0.000000 0.000000 ( 0.000009)
38
+ # >> >>>>> n: 1000
39
+ # >> user system total real
40
+ # >> split map: 0.000000 0.000000 0.000000 ( 0.002310)
41
+ # >> gsub: 0.010000 0.000000 0.010000 ( 0.006667)
42
+ # >> camelcase: 0.000000 0.000000 0.000000 ( 0.000013)
43
+ # >> >>>>> n: 10000
44
+ # >> user system total real
45
+ # >> split map: 0.020000 0.000000 0.020000 ( 0.025425)
46
+ # >> gsub: 0.070000 0.000000 0.070000 ( 0.070857)
47
+ # >> camelcase: 0.000000 0.000000 0.000000 ( 0.000013)
48
+ # >> >>>>> n: 100000
49
+ # >> user system total real
50
+ # >> split map: 0.260000 0.000000 0.260000 ( 0.254333)
51
+ # >> gsub: 0.670000 0.000000 0.670000 ( 0.681261)
52
+ # >> camelcase: 0.000000 0.000000 0.000000 ( 0.000012)
53
+ # >> >>>>> n: 1000000
54
+ # >> user system total real
55
+ # >> split map: 2.570000 0.000000 2.570000 ( 2.579100)
56
+ # >> gsub: 6.790000 0.000000 6.790000 ( 6.839046)
57
+ # >> camelcase: 0.000000 0.000000 0.000000 ( 0.000012)
data/string_plus.gemspec CHANGED
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.8"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "matest"
24
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Iachetti
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: matest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Some extra methods for strings.
42
56
  email:
43
57
  - iachetti.federico@gmail.com
@@ -54,7 +68,10 @@ files:
54
68
  - bin/console
55
69
  - bin/setup
56
70
  - lib/string_plus.rb
71
+ - lib/string_plus/benchmarks.rb
57
72
  - lib/string_plus/version.rb
73
+ - lib/string_plus/xmptmp-in2759NpU.rb
74
+ - lib/string_plus/xmptmp-out2759aza.rb
58
75
  - string_plus.gemspec
59
76
  homepage: https://github.com/iachettifederico/string_plus
60
77
  licenses: