snake_camel 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -1
- data/lib/snake_camel/instance_methods.rb +9 -0
- data/lib/snake_camel/methods.rb +9 -1
- data/lib/snake_camel/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87b2c2d56313835f2cda5993ccc8053b3d47ef7d
|
4
|
+
data.tar.gz: 026f016ae292ab0e6b152d936ac549d22118a0ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a7aaf0c91edf2b95867d62581355c8ef3e7621d47eb826f42573d4f5e5962adfa8912ef1c08592a1f48f1c817ecfbada5eb5bdc9e27619992e8ec0338ebef0a
|
7
|
+
data.tar.gz: d10bfa7d94e1f59add5adb9755b70260db9da6cdd051865375ac018ca33cdb834164046df8b31d0f8e0265b4e6ec18136984d833d75e4e59d5cdf7d5573eb366
|
data/README.md
CHANGED
@@ -21,9 +21,20 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
+
### Available methods:
|
25
|
+
|
26
|
+
- snakecase
|
27
|
+
|
28
|
+
- snakecase!
|
29
|
+
|
30
|
+
- camelcase
|
31
|
+
|
32
|
+
- camelcase!
|
33
|
+
|
34
|
+
|
24
35
|
You have several ways to use it, it's pretty simple. Choose one, based on your need!
|
25
36
|
|
26
|
-
- If you don't care about the
|
37
|
+
- If you don't care about what's under the hood:
|
27
38
|
|
28
39
|
```ruby
|
29
40
|
require 'snake_camel'
|
@@ -62,6 +73,7 @@ SnakeCamel::Methods.snakecase('FooBar') #=> foo_bar
|
|
62
73
|
SnakeCamel::Methods.camelcase('foo_bar') #=> FooBar
|
63
74
|
```
|
64
75
|
|
76
|
+
|
65
77
|
## Creator's notes
|
66
78
|
|
67
79
|
I know there are other gems that provide the same functionality as SnakeCamel, but I want to create something more gentle, more simple.
|
@@ -7,8 +7,17 @@ module SnakeCamel
|
|
7
7
|
SnakeCamel::Methods.snakecase(self)
|
8
8
|
end
|
9
9
|
|
10
|
+
def snakecase!
|
11
|
+
SnakeCamel::Methods.snakecase!(self)
|
12
|
+
end
|
13
|
+
|
10
14
|
def camelcase
|
11
15
|
SnakeCamel::Methods.camelcase(self)
|
12
16
|
end
|
17
|
+
|
18
|
+
def camelcase!
|
19
|
+
SnakeCamel::Methods.camelcase!(self)
|
20
|
+
end
|
21
|
+
|
13
22
|
end
|
14
23
|
end
|
data/lib/snake_camel/methods.rb
CHANGED
@@ -3,13 +3,21 @@ module SnakeCamel
|
|
3
3
|
module Methods
|
4
4
|
extend self
|
5
5
|
|
6
|
+
def snakecase!(string)
|
7
|
+
string.replace(string.to_s.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase)
|
8
|
+
end
|
9
|
+
|
6
10
|
def snakecase(string)
|
7
|
-
string.
|
11
|
+
snakecase!(string.dup)
|
8
12
|
end
|
9
13
|
|
10
14
|
def camelcase(string)
|
11
15
|
string.to_s.split('_').each { |e| e.capitalize! }.join
|
12
16
|
end
|
13
17
|
|
18
|
+
def camelcase!(string)
|
19
|
+
string.replace(camelcase(string))
|
20
|
+
end
|
21
|
+
|
14
22
|
end
|
15
23
|
end
|
data/lib/snake_camel/version.rb
CHANGED