string_plus 0.4.0 → 0.4.1

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: e72cee50eeed4fcfe0f1a2d5903030ddc923ab9e
4
- data.tar.gz: c078be114ac0e278aa4c29ac8d84eb549b28981c
3
+ metadata.gz: d9b049a7394da5db32c0584bb45b53a47e928488
4
+ data.tar.gz: 4fc8e26c0032b35dcf08d3c6e845afb323f06c9c
5
5
  SHA512:
6
- metadata.gz: 33daf1f78e882bd3286798e049dbadd14b76d5ee62f74ac0ee96c7abd3e95acb465f1f3a26248e3c5c7be4cb289d01dd66e5ce4c1e6dccd02e3e81991822c533
7
- data.tar.gz: 4aca017a5b34c69fd952d3904e8933715a29e7481595808bb5cf3d67b4dc07075453d01331024f880b77eb097edda3680c2704f0dc7f0d2640c28edb17756d78
6
+ metadata.gz: 0428da76292a7ca2698663ae2856eabae2dc0959821a9a834aeacaf9ec60fdc462a02efbbd50307aa80faf9123c6c088829ac367a1d418701c7b46d275bf94a3
7
+ data.tar.gz: de9219e49a1d155ce0ea0b26fc1333b0fd65c3ebad8985994e15ccb89e37e0d81f4780ebc8424c31bbcd33c7c735b7acf4f1819c6b38a8bf771b4b2330243166
data/lib/string_plus.rb CHANGED
@@ -21,10 +21,11 @@ module StringPlus
21
21
  end
22
22
 
23
23
  def underscore
24
+ return self.downcase if self.each_char.all? { |c| c == c.upcase && c =~ /[a-zA-Z0-9]/}
24
25
  res = ""
25
26
  [nil, *self.each_char].each_cons(2) do |last, current|
26
- res << "_" if current == current.upcase && last != nil
27
- res << current.downcase
27
+ res << "_" if last !=nil && current == current.upcase && !("0".."9").include?(current)
28
+ res << current.downcase unless current == " "
28
29
  end
29
30
  res
30
31
  end
@@ -1,3 +1,3 @@
1
1
  module StringPlus
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Iachetti
@@ -70,8 +70,6 @@ files:
70
70
  - lib/string_plus.rb
71
71
  - lib/string_plus/benchmarks.rb
72
72
  - lib/string_plus/version.rb
73
- - lib/string_plus/xmptmp-in2759NpU.rb
74
- - lib/string_plus/xmptmp-out2759aza.rb
75
73
  - string_plus.gemspec
76
74
  homepage: https://github.com/iachettifederico/string_plus
77
75
  licenses:
@@ -1,36 +0,0 @@
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:
@@ -1,57 +0,0 @@
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)