to_camel_case 1.0.0
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.
- data/CHANGELOG.rdoc +4 -0
- data/README.md +48 -0
- data/README.rdoc +46 -0
- data/lib/to_camel_case.rb +19 -0
- data/lib/to_camel_case/ToCamelCase.rb +78 -0
- data/spec/ToCamelCase/String_spec.rb +26 -0
- metadata +50 -0
data/CHANGELOG.rdoc
ADDED
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# ToCamelCase #
|
2
|
+
|
3
|
+
http://rubygems.org/gems/to_camel_case
|
4
|
+
|
5
|
+
# Description #
|
6
|
+
|
7
|
+
Converts strings like "to_camel_case" into Camel Case: "ToCamelCase".
|
8
|
+
|
9
|
+
# Summary #
|
10
|
+
|
11
|
+
Provides :to_camel_case to String via module ToCamelCase.
|
12
|
+
|
13
|
+
# Install #
|
14
|
+
|
15
|
+
* sudo gem install to_camel_case
|
16
|
+
|
17
|
+
# Usage #
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
'some_random_string'.to_camel_case
|
21
|
+
|
22
|
+
# => 'ToCamelCase'
|
23
|
+
```
|
24
|
+
|
25
|
+
# License #
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) Asher
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
== ToCamelCase
|
2
|
+
|
3
|
+
http://rubygems.org/gems/to_camel_case
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
Converts strings like "to_camel_case" into Camel Case: "ToCamelCase".
|
8
|
+
|
9
|
+
== Summary
|
10
|
+
|
11
|
+
Provides :to_camel_case to String via module ToCamelCase.
|
12
|
+
|
13
|
+
== Install
|
14
|
+
|
15
|
+
* sudo gem install to_camel_case
|
16
|
+
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
'some_random_string'.to_camel_case
|
20
|
+
|
21
|
+
# => 'ToCamelCase'
|
22
|
+
|
23
|
+
== License
|
24
|
+
|
25
|
+
(The MIT License)
|
26
|
+
|
27
|
+
Copyright (c) Asher
|
28
|
+
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
30
|
+
a copy of this software and associated documentation files (the
|
31
|
+
'Software'), to deal in the Software without restriction, including
|
32
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
33
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
34
|
+
permit persons to whom the Software is furnished to do so, subject to
|
35
|
+
the following conditions:
|
36
|
+
|
37
|
+
The above copyright notice and this permission notice shall be
|
38
|
+
included in all copies or substantial portions of the Software.
|
39
|
+
|
40
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
41
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
42
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
43
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
44
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
45
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
46
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
module ::ToCamelCase
|
3
|
+
end
|
4
|
+
|
5
|
+
basepath = 'to_camel_case/ToCamelCase'
|
6
|
+
|
7
|
+
files = [
|
8
|
+
|
9
|
+
]
|
10
|
+
|
11
|
+
files.each do |this_file|
|
12
|
+
require_relative( File.join( basepath, this_file ) + '.rb' )
|
13
|
+
end
|
14
|
+
|
15
|
+
require_relative( basepath + '.rb' )
|
16
|
+
|
17
|
+
class ::String
|
18
|
+
include ::ToCamelCase
|
19
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
|
2
|
+
module ::ToCamelCase
|
3
|
+
|
4
|
+
###################
|
5
|
+
# to_camel_case #
|
6
|
+
###################
|
7
|
+
|
8
|
+
def to_camel_case
|
9
|
+
|
10
|
+
camel_case_string = ''
|
11
|
+
|
12
|
+
upcase_next_char = true
|
13
|
+
|
14
|
+
chars.each do |this_char|
|
15
|
+
|
16
|
+
if this_char == '_'
|
17
|
+
|
18
|
+
upcase_next_char = true
|
19
|
+
|
20
|
+
else
|
21
|
+
|
22
|
+
if upcase_next_char
|
23
|
+
# we use upcase! to avoid creating a duplicate string from this_char
|
24
|
+
this_char.upcase!
|
25
|
+
camel_case_string << this_char
|
26
|
+
upcase_next_char = false
|
27
|
+
else
|
28
|
+
camel_case_string << this_char
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
return camel_case_string
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
####################
|
40
|
+
# to_camel_case! #
|
41
|
+
####################
|
42
|
+
|
43
|
+
def to_camel_case!
|
44
|
+
|
45
|
+
upcase_next_char = true
|
46
|
+
|
47
|
+
delete_indexes = [ ]
|
48
|
+
|
49
|
+
chars.each_with_index do |this_char, index|
|
50
|
+
|
51
|
+
if this_char == '_'
|
52
|
+
|
53
|
+
upcase_next_char = true
|
54
|
+
delete_indexes.push( index )
|
55
|
+
|
56
|
+
else
|
57
|
+
|
58
|
+
if upcase_next_char
|
59
|
+
# we use upcase! to avoid creating a duplicate string from this_char
|
60
|
+
this_char.upcase!
|
61
|
+
self[ index ] = this_char
|
62
|
+
upcase_next_char = false
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
until delete_indexes.empty?
|
70
|
+
this_delete_index = delete_indexes.pop
|
71
|
+
slice!( this_delete_index )
|
72
|
+
end
|
73
|
+
|
74
|
+
return self
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
require_relative '../../lib/to_camel_case.rb'
|
3
|
+
|
4
|
+
describe ::ToCamelCase do
|
5
|
+
|
6
|
+
###################
|
7
|
+
# to_camel_case #
|
8
|
+
###################
|
9
|
+
|
10
|
+
it 'can return a duplicate in camel case' do
|
11
|
+
string = 'under_score_string'
|
12
|
+
string.to_camel_case.should == 'UnderScoreString'
|
13
|
+
string.should == 'under_score_string'
|
14
|
+
end
|
15
|
+
|
16
|
+
####################
|
17
|
+
# to_camel_case! #
|
18
|
+
####################
|
19
|
+
|
20
|
+
it 'can modify itself to be camel case' do
|
21
|
+
string = 'under_score_string'
|
22
|
+
string.to_camel_case!.should == 'UnderScoreString'
|
23
|
+
string.should == 'UnderScoreString'
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: to_camel_case
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Asher
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-10 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'Converts strings like "to_camel_case" into Camel Case: "ToCamelCase".'
|
15
|
+
email: asher@ridiculouspower.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/to_camel_case/ToCamelCase.rb
|
21
|
+
- lib/to_camel_case.rb
|
22
|
+
- spec/ToCamelCase/String_spec.rb
|
23
|
+
- README.md
|
24
|
+
- README.rdoc
|
25
|
+
- CHANGELOG.rdoc
|
26
|
+
homepage: http://rubygems.org/gems/to_camel_case
|
27
|
+
licenses: []
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project: to_camel_case
|
46
|
+
rubygems_version: 1.8.23
|
47
|
+
signing_key:
|
48
|
+
specification_version: 3
|
49
|
+
summary: Provides :to_camel_case to String via module ToCamelCase.
|
50
|
+
test_files: []
|