string_plus 0.3.1 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b16284eb93cb50681c38e69d65d1feca82de961a
4
- data.tar.gz: e76f06046520281aff0a8a829617df90228a9f28
3
+ metadata.gz: e72cee50eeed4fcfe0f1a2d5903030ddc923ab9e
4
+ data.tar.gz: c078be114ac0e278aa4c29ac8d84eb549b28981c
5
5
  SHA512:
6
- metadata.gz: e58cb6ec1b4bbc62d1ddf6cc78c2bf46ca4744ad86a46b59fee861dbbcfdbb35605d0242d7ca11dea3bc016215fbf06dad1894bae5f4fdc009d9a7e3a11df3b5
7
- data.tar.gz: 7aef5df18af8895b705691843682b05887316e6344894def360e655bf3d928e5e0c3771de1e384d319e454883ad4f21062127e00460ee59437a4be2f98dbb4fc
6
+ metadata.gz: 33daf1f78e882bd3286798e049dbadd14b76d5ee62f74ac0ee96c7abd3e95acb465f1f3a26248e3c5c7be4cb289d01dd66e5ce4c1e6dccd02e3e81991822c533
7
+ data.tar.gz: 4aca017a5b34c69fd952d3904e8933715a29e7481595808bb5cf3d67b4dc07075453d01331024f880b77eb097edda3680c2704f0dc7f0d2640c28edb17756d78
data/README.md CHANGED
@@ -9,9 +9,10 @@ Some stuff I like on `String`s.
9
9
  Convert a space/underscore-separated String into camel case.
10
10
 
11
11
  ```ruby
12
- require "string_plus"
13
- "hello_cool_world".camelcase
14
- # => "HelloCoolWorld"
12
+ require "string_plus"
13
+
14
+ "hello_cool_world".camelcase
15
+ # => "HelloCoolWorld"
15
16
  ```
16
17
 
17
18
  ### `#lcamelcase`
@@ -19,9 +20,10 @@ require "string_plus"
19
20
  Convert a space/underscore-separated String into lower camel case.
20
21
 
21
22
  ```ruby
22
- require "string_plus"
23
- "hello_cool_world".lcamelcase
24
- # => "helloCoolWorld"
23
+ require "string_plus"
24
+
25
+ "hello_cool_world".lcamelcase
26
+ # => "helloCoolWorld"
25
27
  ```
26
28
 
27
29
 
@@ -35,11 +37,28 @@ Acknowledgments:
35
37
  * You're not creating a Constant, but retrieving it. So, if it doesn't already exist, it will raise an error.
36
38
 
37
39
  ```ruby
38
- require "string_plus"
39
- "basic_object".constantize
40
- # => BasicObject
40
+ require "string_plus"
41
+
42
+ "basic_object".constantize
43
+ # => BasicObject
41
44
  ```
42
45
 
46
+ It also accepts nested constants, separated by `-`
47
+
48
+ ```ruby
49
+ require "string_plus"
50
+
51
+ module ExternalModule
52
+ class InternalClass
53
+ class InceptionedClass
54
+ class DreamInsideADreamInsideADream; end
55
+ end
56
+ end
57
+ end
58
+
59
+ "external_module-internal_class-inceptioned_class-dream_inside_a_dream_inside_a_dream".constantize
60
+ # => ExternalModule::InternalClass::InceptionedClass::DreamInsideADreamInsideADream
61
+ ```
43
62
 
44
63
  ## Installation
45
64
 
data/lib/string_plus.rb CHANGED
@@ -20,6 +20,16 @@ module StringPlus
20
20
  camelcase(false)
21
21
  end
22
22
 
23
+ def underscore
24
+ res = ""
25
+ [nil, *self.each_char].each_cons(2) do |last, current|
26
+ res << "_" if current == current.upcase && last != nil
27
+ res << current.downcase
28
+ end
29
+ res
30
+ end
31
+ alias :snakecase :underscore
32
+
23
33
  def constantize
24
34
  c = self.split("-").map(&:camelcase).join("::")
25
35
  Object.send(:const_get, c)
@@ -1,3 +1,3 @@
1
1
  module StringPlus
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.1
4
+ version: 0.4.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-05 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler