aromat 1.1.2 → 1.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 +47 -0
- data/lib/aromat.rb +2 -0
- data/lib/aromat/case.rb +34 -0
- data/lib/aromat/module.rb +13 -0
- data/lib/aromat/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdd0673a61daeff34e4e9c4e7011f4c0f027f1cc
|
4
|
+
data.tar.gz: fac0faab362433e49fee6434300e31175c2c68cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a281081c2523cfaaf6f007a3ef61c8366d1b6205ae902c5e369869af11f0d638c49bdbf08c45b74c5e12745372f2ddd33432985d709516e80bbb9af0f70252db
|
7
|
+
data.tar.gz: 800f058b4d91fd2f0b712b7e404b2dbb214aa393f81a76a5379fcd2cb9c81c53d78a1430a06707746e217a141c21870bd31a8334a6ae77753ae9eeae737cd103
|
data/README.md
CHANGED
@@ -99,6 +99,53 @@ nil.try :nstr
|
|
99
99
|
# => 'bar'
|
100
100
|
```
|
101
101
|
|
102
|
+
### String Case Conversions
|
103
|
+
|
104
|
+
Case-conversion methods are monkey-patched into the *String* class. The following methods are made available:
|
105
|
+
* camelcase ('foo-bar' => 'FooBar')
|
106
|
+
* snakecase ('FooBar' => 'foo-bar')
|
107
|
+
* kebabcase ('FooBar' => 'foo_bar')
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
'foo_bar'.camelcase
|
111
|
+
# => 'FooBar'
|
112
|
+
'foo-bar'.camelcase
|
113
|
+
# => 'FooBar'
|
114
|
+
|
115
|
+
'FooBar'.snakecase
|
116
|
+
# => 'foo-bar'
|
117
|
+
'foo_bar'.snakecase
|
118
|
+
# => 'foo-bar'
|
119
|
+
|
120
|
+
'FooBar'.kebabcase
|
121
|
+
# => 'foo_bar'
|
122
|
+
'foo-bar'.kebabcase
|
123
|
+
# => 'foo_bar'
|
124
|
+
```
|
125
|
+
|
126
|
+
### Get Module Name
|
127
|
+
|
128
|
+
A _mod_name_ method is monkey-patched into the *Module* class. This allows obtaining the name of any module, without its hierarchical tree.
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
module Foo
|
132
|
+
module Bar
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
Foo.name
|
137
|
+
# => 'Foo'
|
138
|
+
|
139
|
+
Foo.mod_name
|
140
|
+
# => 'Foo'
|
141
|
+
|
142
|
+
Foo::Bar.name
|
143
|
+
# => 'Foo::Bar'
|
144
|
+
|
145
|
+
Foo::Bar.mod_name # <= This is where it gets interesting
|
146
|
+
# => 'Bar'
|
147
|
+
```
|
148
|
+
|
102
149
|
### Time Duration
|
103
150
|
|
104
151
|
A _duration_ method is monkey-patched into the 'Numeric' class. This method returns a textual string representation of the time duration.
|
data/lib/aromat.rb
CHANGED
data/lib/aromat/case.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Aromat
|
2
|
+
# by Eresse <eresse@eresse.net>
|
3
|
+
|
4
|
+
# Monkey-patch String Class
|
5
|
+
class String
|
6
|
+
|
7
|
+
# Camel Case:
|
8
|
+
# Converts String to CamelCase.
|
9
|
+
# @return [String] The string converted to camel-case
|
10
|
+
def camelcase
|
11
|
+
self.gsub(/(^|[_-])([a-zA-Z])/) { |s| s[/[a-zA-Z]$/].upcase }
|
12
|
+
end
|
13
|
+
|
14
|
+
# Kebab Case:
|
15
|
+
# Converts String to kebab-case.
|
16
|
+
# @return [String] The string converted to kebab-case
|
17
|
+
def kebabcase
|
18
|
+
flatcase '-'
|
19
|
+
end
|
20
|
+
|
21
|
+
# Snake Case:
|
22
|
+
# Converts String to snake_case.
|
23
|
+
def snakecase
|
24
|
+
flatcase '_'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Flat Case:
|
28
|
+
# Generic String converter for kebab-case / snake_case.
|
29
|
+
# @param [String] delim Delimiter to be placed between parts
|
30
|
+
# @return [String] The string converted to flatcase.
|
31
|
+
def flatcase delim = ''
|
32
|
+
self.gsub(/((^|[a-z])[A-Z])|([_-][a-zA-Z])/) { |s| (s.length > 1 ? "#{s[/^[a-z]/]}#{delim}" : '') + s[/[a-zA-Z]$/].downcase }
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Aromat
|
2
|
+
# by Eresse <eresse@eresse.net>
|
3
|
+
|
4
|
+
# Monkey-patch Module Class
|
5
|
+
class Module
|
6
|
+
|
7
|
+
# Module Name:
|
8
|
+
# Returns the name of the Module, without its hierarchical tree.
|
9
|
+
# @return [String] The name of the Module
|
10
|
+
def mod_name
|
11
|
+
name[/[^:]+$/]
|
12
|
+
end
|
13
|
+
end
|
data/lib/aromat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aromat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eresse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,8 +66,10 @@ files:
|
|
66
66
|
- Rakefile
|
67
67
|
- aromat.gemspec
|
68
68
|
- lib/aromat.rb
|
69
|
+
- lib/aromat/case.rb
|
69
70
|
- lib/aromat/dclone.rb
|
70
71
|
- lib/aromat/duration.rb
|
72
|
+
- lib/aromat/module.rb
|
71
73
|
- lib/aromat/nstr.rb
|
72
74
|
- lib/aromat/pad.rb
|
73
75
|
- lib/aromat/sym_keys.rb
|