string_plus 0.4.1 → 0.5.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: d9b049a7394da5db32c0584bb45b53a47e928488
4
- data.tar.gz: 4fc8e26c0032b35dcf08d3c6e845afb323f06c9c
3
+ metadata.gz: a14cb253d8ecaaca70ac12b736aae39f476bb303
4
+ data.tar.gz: 424b1c5d4adae7bbd0bd99482bd645331e804d6e
5
5
  SHA512:
6
- metadata.gz: 0428da76292a7ca2698663ae2856eabae2dc0959821a9a834aeacaf9ec60fdc462a02efbbd50307aa80faf9123c6c088829ac367a1d418701c7b46d275bf94a3
7
- data.tar.gz: de9219e49a1d155ce0ea0b26fc1333b0fd65c3ebad8985994e15ccb89e37e0d81f4780ebc8424c31bbcd33c7c735b7acf4f1819c6b38a8bf771b4b2330243166
6
+ metadata.gz: 3deeac212bb1a706b85bd5a6fc460fcf9abd15d7d86ec610299265a75eeb76c39d04247b8907947a9eb50490cf41bc9c330c6c3f0091748e332e2b6344f8fb7a
7
+ data.tar.gz: c79dcd4a71e1f2edfbc299bdc9e49ef9a28813ce91a8026c95903d2a044681b4a2126a4781d12cbad772cdda0ef33350ec731bdcb8998148a073449553fa6fec
@@ -0,0 +1,81 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "string_plus"
3
+
4
+ class String
5
+ def camelcase_linear
6
+ res = ""
7
+ flag = true
8
+ self.each_char {|w|
9
+ (flag = true ; next) if w == "_" || w == " "
10
+ res << if flag
11
+ flag = false
12
+ w.upcase
13
+ else
14
+ w
15
+ end
16
+ }
17
+ res
18
+ end
19
+
20
+ def camelcase_array
21
+ split("_").map(&:capitalize).join
22
+ end
23
+
24
+ def camelcase_array2
25
+ split(/[-_\s]*/).map(&:capitalize).join
26
+ end
27
+
28
+ def camelcase_regex
29
+ gsub(/^\w|[\W_]+?\w/) { |match| match[-1,1].upcase }
30
+ end
31
+
32
+ def camelcase_regex2
33
+ gsub(/^\w|[\W_]+\w/) { |match| match[-1,1].upcase }
34
+ end
35
+ end
36
+
37
+ str = <<EOF
38
+ Lorem 000 00ipsum, dolor-=+_sit amet, consectetur adipiscing elit. Praesent augue velit, aliquet vel sollicitudin vel, efficitur et augue. Quisque a sem sodales, accumsan lorem ac, rhoncus lorem. Vestibulum ultrices dolor in dui pulvinar, eget sagittis magna aliquet. Donec dapibus in lorem vel malesuada. Ut suscipit imperdiet venenatis. Ut gravida lorem nibh, vel cursus nulla finibus non. Fusce at lorem tincidunt, consequat justo ac, commodo lorem. Mauris eu ligula sollicitudin, pellentesque erat accumsan, rutrum quam. Cras maximus faucibus massa, tincidunt lacinia lacus cursus ac. Curabitur felis erat, tincidunt a aliquam non, semper scelerisque leo. In pellentesque mollis gravida.
39
+ Vestibulum semper accumsan nulla. Mauris vel metus sollicitudin, hendrerit mi dictum, dignissim magna. Nullam tincidunt dapibus metus, sed lacinia augue volutpat ultricies. Proin bibendum enim sed neque lobortis, vel iaculis enim fermentum. Vivamus quis nulla tincidunt, congue velit interdum, sagittis lectus. Integer imperdiet, ante non venenatis semper, nulla nisi convallis tortor, ut porttitor lorem mi nec orci. Etiam id condimentum mauris.
40
+ hasellus tempus sit amet lectus sed tincidunt. Mauris egestas volutpat diam eget convallis. Etiam sit amet ante finibus, finibus lectus sit amet, imperdiet diam. Vivamus vestibulum est nec lacus egestas sollicitudin. Sed fringilla malesuada pellentesque. Quisque in vulputate urna. Proin iaculis sem ut tincidunt condimentum. Ut urna massa, sollicitudin ac vehicula sed, vestibulum non nisi. Mauris iaculis lacinia dolor, id varius sem luctus sed. Vestibulum non mauris sagittis mauris porttitor luctus."
41
+ EOF
42
+
43
+ str.camelcase_regex
44
+ # => "Lorem00000ipsumDolor_sitAmetConsecteturAdipiscingElitPraesentAugueVelitAliquetVelSollicitudinVelEfficiturEtAugueQuisqueASemSodalesAccumsanLoremAcRhoncusLoremVestibulumUltricesDolorInDuiPulvinarEgetSagittisMagnaAliquetDonecDapibusInLoremVelMalesuadaUtSuscipitImperdietVenenatisUtGravidaLoremNibhVelCursusNullaFinibusNonFusceAtLoremTinciduntConsequatJustoAcCommodoLoremMaurisEuLigulaSollicitudinPellentesqueEratAccumsanRutrumQuamCrasMaximusFaucibusMassaTinciduntLaciniaLacusCursusAcCurabiturFelisEratTinciduntAAliquamNonSemperScelerisqueLeoInPellentesqueMollisGravidaVestibulumSemperAccumsanNullaMaurisVelMetusSollicitudinHendreritMiDictumDignissimMagnaNullamTinciduntDapibusMetusSedLaciniaAugueVolutpatUltriciesProinBibendumEnimSedNequeLobortisVelIaculisEnimFermentumVivamusQuisNullaTinciduntCongueVelitInterdumSagittisLectusIntegerImperdietAnteNonVenenatisSemperNullaNisiConvallisTortorUtPorttitorLoremMiNecOrciEtiamIdCondimentumMaurisHasellusTempusSitAmetLectusSedTinciduntMaurisEgestasVolutpatDiamEgetConvallisEtiamSitAmetAnteFinibusFinibusLectusSitAmetImperdietDiamVivamusVestibulumEstNecLacusEgestasSollicitudinSedFringillaMalesuadaPellentesqueQuisqueInVulputateUrnaProinIaculisSemUtTinciduntCondimentumUtUrnaMassaSollicitudinAcVehiculaSedVestibulumNonNisiMaurisIaculisLaciniaDolorIdVariusSemLuctusSedVestibulumNonMaurisSagittisMaurisPorttitorLuctus.\"\n"
45
+
46
+ require 'benchmark/ips'
47
+
48
+ Benchmark.ips do |x|
49
+ # Configure the number of seconds used during
50
+ # the warmup phase (default 2) and calculation phase (default 5)
51
+ x.config(time: 5, warmup: 2)
52
+
53
+ # Typical mode, runs the block as many times as it can
54
+ x.report("linear") { str.camelcase_linear }
55
+ x.report("array") { str.camelcase_array }
56
+ x.report("array2") { str.camelcase_array2 }
57
+ x.report("regex") { str.camelcase_regex }
58
+ x.report("regex2") { str.camelcase_regex2 }
59
+
60
+ x.compare!
61
+ end
62
+ # >> Calculating -------------------------------------
63
+ # >> linear 119.000 i/100ms
64
+ # >> array 2.963k i/100ms
65
+ # >> array2 82.000 i/100ms
66
+ # >> regex 350.000 i/100ms
67
+ # >> regex2 330.000 i/100ms
68
+ # >> -------------------------------------------------
69
+ # >> linear 1.198k (± 6.4%) i/s - 6.069k
70
+ # >> array 30.752k (± 5.5%) i/s - 154.076k
71
+ # >> array2 818.688 (± 4.4%) i/s - 4.100k
72
+ # >> regex 3.494k (± 5.4%) i/s - 17.500k
73
+ # >> regex2 3.311k (± 4.7%) i/s - 16.830k
74
+ # >>
75
+ # >> Comparison:
76
+ # >> array: 30752.1 i/s
77
+ # >> regex: 3493.6 i/s - 8.80x slower
78
+ # >> regex2: 3310.6 i/s - 9.29x slower
79
+ # >> linear: 1197.6 i/s - 25.68x slower
80
+ # >> array2: 818.7 i/s - 37.56x slower
81
+ # >>
@@ -1,3 +1,3 @@
1
1
  module StringPlus
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/string_plus.rb CHANGED
@@ -36,5 +36,3 @@ module StringPlus
36
36
  Object.send(:const_get, c)
37
37
  end
38
38
  end
39
-
40
- String.send(:include, StringPlus)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Iachetti
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,6 +65,7 @@ files:
65
65
  - LICENSE.txt
66
66
  - README.md
67
67
  - Rakefile
68
+ - benchmarks/benchmarks.rb
68
69
  - bin/console
69
70
  - bin/setup
70
71
  - lib/string_plus.rb
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  version: '0'
92
93
  requirements: []
93
94
  rubyforge_project:
94
- rubygems_version: 2.4.6
95
+ rubygems_version: 2.4.8
95
96
  signing_key:
96
97
  specification_version: 4
97
98
  summary: Some extra methods for strings.