simple_symbolize 3.0.0 → 4.1.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 +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/.github/workflows/ruby_gem.yml +1 -1
- data/.rubocop.yml +4 -1
- data/.ruby-version +1 -1
- data/Gemfile +5 -0
- data/README.md +53 -5
- data/lib/simple_symbolize/core_ext/string/symbolize.rb +36 -0
- data/lib/simple_symbolize/core_ext/symbol/symbolize.rb +36 -0
- data/lib/simple_symbolize/version.rb +1 -1
- data/lib/simple_symbolize.rb +40 -16
- data/simple_symbolize.gemspec +1 -9
- metadata +9 -63
- data/lib/simple_symbolize/string.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fe69f67b8c3e4152dd088e6425f0a0e9c0c5206ff384bd599284f976b664e4e
|
4
|
+
data.tar.gz: d8ce3414da304b386a71e83f482bd3dc2a031274c61dbe8d69efbab1d9dc819a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da85cabac7e7f368cfd7a0366dffa7642e6f0b27f2cbac49b548264df55f82eb715d74cf80e2113a172b7451b2496a86ddcbc13ef818d66e8b7f72aa8df80ff1
|
7
|
+
data.tar.gz: 82a0bd3a48cecbf2ca49607dd136cc8dc46a3babb761507b88a74043a494f396fbe6e7ecc53393c5a2d065e2f8d0302ccfdf80dfe6cb2412d3188091f15d2f44
|
data/.github/workflows/ruby.yml
CHANGED
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.4.5
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -17,7 +17,7 @@ It works by removing special characters in a String like `'!'` and underscoring
|
|
17
17
|
'hello world!'.to_sym # => :"hello world!"
|
18
18
|
|
19
19
|
# Symbolize gem
|
20
|
-
'hello world!'.
|
20
|
+
'hello world!'.simple_symbolize # => :hello_world
|
21
21
|
```
|
22
22
|
|
23
23
|
## Installation
|
@@ -53,7 +53,19 @@ SimpleSymbolize.symbolize('hello world!') # => :hello_world
|
|
53
53
|
```ruby
|
54
54
|
require 'simple_symbolize'
|
55
55
|
|
56
|
-
|
56
|
+
String.include SimpleSymbolize::CoreExt::String
|
57
|
+
|
58
|
+
'hello world!'.simple_symbolize # => :hello_world
|
59
|
+
```
|
60
|
+
|
61
|
+
### Call the symbolize method on your Symbol object
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
require 'simple_symbolize'
|
65
|
+
|
66
|
+
Symbol.include SimpleSymbolize::CoreExt::Symbol
|
67
|
+
|
68
|
+
:hello_world!.simple_symbolize # => :hello_world
|
57
69
|
```
|
58
70
|
|
59
71
|
## Configuration
|
@@ -72,15 +84,51 @@ end
|
|
72
84
|
|
73
85
|
## Updates!
|
74
86
|
|
87
|
+
### V4.1
|
88
|
+
### Symbol methods can now be Mixed in
|
89
|
+
|
90
|
+
SimpleSymbolize now supports mixing in the methods on the Symbol class, allowing you to call `simple_symbolize` directly on a Symbol object.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
Symbol.include SimpleSymbolize::CoreExt::Symbol
|
94
|
+
:hello_world!.simple_symbolize # => :hello_world
|
95
|
+
```
|
96
|
+
|
97
|
+
### V4
|
98
|
+
#### String methods now need to be Mixed in
|
99
|
+
|
100
|
+
SimpleSymbolize is safe to use with other gems, particularly the popular ActiveSupport gem which SimpleSymbolize use to share
|
101
|
+
certain methods names with.
|
102
|
+
|
103
|
+
You now need to deliberately mixin the methods on the String class:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
String.include SimpleSymbolize::CoreExt::String
|
107
|
+
```
|
108
|
+
|
109
|
+
To make them easier to spot, the method names on the String class have been prefixed with `simple_` to avoid confusion.
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
'Hello World!'.simple_symbolize #=> :hello_world
|
113
|
+
'Hello World!'.simple_elementize #=> 'hello_world'
|
114
|
+
'Hello World!'.simple_camelize #=> :helloWorld
|
115
|
+
'Hello World!'.simple_snakeize #=> :hello_world
|
116
|
+
```
|
117
|
+
|
118
|
+
#### Introducing #snakeize
|
119
|
+
|
120
|
+
The `#snakeize` method will return your object in snake_case.
|
121
|
+
This is the default behaviour of the `#symbolize` method however `#snakeize` will always return thr Symbol in snake_case.
|
122
|
+
|
75
123
|
### V3
|
76
|
-
#### String to_snake_case
|
124
|
+
#### String to_snake_case [DEPRECATED - replaced with `#simple_snakeize` in v4]
|
77
125
|
|
78
126
|
`#to_snake_case` extends the String class to return you your String object in snake_case format.
|
79
127
|
|
80
128
|
#### Handle camelCase with Symbolize
|
81
129
|
|
82
130
|
```ruby
|
83
|
-
symbolize('helloWorld!') # => :hello_world
|
131
|
+
SimpleSymbolize.symbolize('helloWorld!') # => :hello_world
|
84
132
|
```
|
85
133
|
|
86
134
|
This is the default behaviour and can be switched off by setting `#handle_camel_case` to `false`
|
@@ -109,7 +157,7 @@ Sometimes you just want a simple String obj without all the fuss. Elementize tak
|
|
109
157
|
and returns you a simple-to-use String.
|
110
158
|
|
111
159
|
```ruby
|
112
|
-
elementize('hello world!') # => "hello_world"
|
160
|
+
SimpleSymbolize.elementize('hello world!') # => "hello_world"
|
113
161
|
```
|
114
162
|
|
115
163
|
#### Camelize
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Extends the String class by mixing in the symbolize module.
|
4
|
+
# @example Mixin the methods to the String class
|
5
|
+
# String.include SimpleSymbolize::CoreExt::String
|
6
|
+
|
7
|
+
module SimpleSymbolize
|
8
|
+
module CoreExt
|
9
|
+
# Contains methods to be mixed into the String class
|
10
|
+
module String
|
11
|
+
# @example Symbolize a string using the String object method
|
12
|
+
# "hello world!".symbolize #=> :hello_world
|
13
|
+
def simple_symbolize
|
14
|
+
SimpleSymbolize.symbolize(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
# @example Turns a String into a camelCase Symbol
|
18
|
+
# "Hello World".simple_camelize => :helloWorld
|
19
|
+
def simple_camelize
|
20
|
+
SimpleSymbolize.camelize(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @example Symbolizes a String then calls #to_s
|
24
|
+
# "helloWorld".simple_elementize => 'hello_word'
|
25
|
+
def simple_elementize
|
26
|
+
SimpleSymbolize.elementize(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @example Turns a String into it's snake_case equivalent
|
30
|
+
# "helloWorld".simple_snakeize => 'hello_word'
|
31
|
+
def simple_snakeize
|
32
|
+
SimpleSymbolize.snakeize(self)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Extends the Symbol class by mixing in the symbolize module.
|
4
|
+
# @example Mixin the methods to the Symbol class
|
5
|
+
# Symbol.include SimpleSymbolize::CoreExt::Symbol
|
6
|
+
|
7
|
+
module SimpleSymbolize
|
8
|
+
module CoreExt
|
9
|
+
# Contains methods to be mixed into the String class
|
10
|
+
module Symbol
|
11
|
+
# @example Symbolize a string using the String object method
|
12
|
+
# :hello_world!.symbolize #=> :hello_world
|
13
|
+
def simple_symbolize
|
14
|
+
SimpleSymbolize.symbolize(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
# @example Turns a String into a camelCase Symbol
|
18
|
+
# :hello_world.simple_camelize => :helloWorld
|
19
|
+
def simple_camelize
|
20
|
+
SimpleSymbolize.camelize(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @example Symbolizes a String then calls #to_s
|
24
|
+
# :helloWorld!.simple_elementize => 'hello_word'
|
25
|
+
def simple_elementize
|
26
|
+
SimpleSymbolize.elementize(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @example Turns a String into it's snake_case equivalent
|
30
|
+
# :helloWorld.simple_snakeize => :hello_word
|
31
|
+
def simple_snakeize
|
32
|
+
SimpleSymbolize.snakeize(self)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/simple_symbolize.rb
CHANGED
@@ -2,10 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'simple_symbolize/version'
|
4
4
|
|
5
|
-
require_relative 'simple_symbolize/string'
|
6
5
|
require_relative 'simple_symbolize/translations'
|
7
|
-
|
8
|
-
|
6
|
+
require_relative 'simple_symbolize/core_ext/string/symbolize'
|
7
|
+
require_relative 'simple_symbolize/core_ext/symbol/symbolize'
|
9
8
|
|
10
9
|
# Main module for the gem
|
11
10
|
# Contains the base methods and allows configuration
|
@@ -31,18 +30,21 @@ module SimpleSymbolize
|
|
31
30
|
# @param obj [Object] the String object to be symbolized.
|
32
31
|
#
|
33
32
|
# @example Symbolize a string using the symbolize method
|
34
|
-
# symbolize("hello world!") #=> :hello_world
|
35
|
-
def symbolize(obj)
|
33
|
+
# SimpleSymbolize.symbolize("hello world!") #=> :hello_world
|
34
|
+
def self.symbolize(obj)
|
36
35
|
return obj unless obj.respond_to?(:to_s)
|
37
36
|
return obj if [Hash, Array, NilClass].include?(obj.class)
|
37
|
+
return obj if obj.respond_to?(:empty?) && obj.empty?
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
obj = if SimpleSymbolize.translations.handle_camel_case
|
40
|
+
snakeize(obj)
|
41
|
+
else
|
42
|
+
obj.to_s
|
43
|
+
.downcase
|
44
|
+
.gsub(Regexp.union(SimpleSymbolize.translations.underscore), '_')
|
45
|
+
.gsub(Regexp.union(SimpleSymbolize.translations.remove), '')
|
46
|
+
end
|
47
|
+
obj.to_sym
|
46
48
|
end
|
47
49
|
|
48
50
|
# Symbolizes a String object and returns it as a String object.
|
@@ -50,10 +52,11 @@ module SimpleSymbolize
|
|
50
52
|
# @param obj [Object] the object to be symbolized.
|
51
53
|
#
|
52
54
|
# @example Elementize a string using the elementize method
|
53
|
-
# elementize("hello world!") #=> "helloWorld"
|
54
|
-
def elementize(obj)
|
55
|
+
# SimpleSymbolize.elementize("hello world!") #=> "helloWorld"
|
56
|
+
def self.elementize(obj)
|
55
57
|
return obj unless obj.respond_to?(:to_s)
|
56
58
|
return obj if [Hash, Array, NilClass].include?(obj.class)
|
59
|
+
return obj if obj.respond_to?(:empty?) && obj.empty?
|
57
60
|
|
58
61
|
symbolize(obj).to_s
|
59
62
|
end
|
@@ -63,14 +66,35 @@ module SimpleSymbolize
|
|
63
66
|
# @param obj [Object] the String object to be camelized.
|
64
67
|
#
|
65
68
|
# @example Camelize a string using the camelize method
|
66
|
-
# camelize("hello world!") #=> :helloWorld
|
67
|
-
def camelize(obj)
|
69
|
+
# SimpleSymbolize.camelize("hello world!") #=> :helloWorld
|
70
|
+
def self.camelize(obj)
|
68
71
|
return obj unless obj.respond_to?(:to_s)
|
69
72
|
return obj if [Hash, Array, NilClass].include?(obj.class)
|
73
|
+
return obj if obj.respond_to?(:empty?) && obj.empty?
|
70
74
|
|
71
75
|
first, *rest = elementize(obj).split('_')
|
72
76
|
return obj if first.nil?
|
73
77
|
|
74
78
|
rest.size.positive? ? (first << rest.map(&:capitalize).join).to_sym : symbolize(first)
|
75
79
|
end
|
80
|
+
|
81
|
+
# Turns a String || Symbol into a snake_case Symbol
|
82
|
+
#
|
83
|
+
# @param obj [Object] the object to be snakeize
|
84
|
+
#
|
85
|
+
# @example Snakeize an object using the snakeize method
|
86
|
+
# SimpleSymbolize.snakeize('Hello World!') #=> :hello_world
|
87
|
+
def self.snakeize(obj)
|
88
|
+
return obj unless obj.respond_to?(:to_s)
|
89
|
+
return obj if [Hash, Array, NilClass].include?(obj.class)
|
90
|
+
return obj if obj.respond_to?(:empty?) && obj.empty?
|
91
|
+
|
92
|
+
obj.to_s
|
93
|
+
.gsub(Regexp.union(SimpleSymbolize.translations.underscore), '_')
|
94
|
+
.gsub(Regexp.union(SimpleSymbolize.translations.remove), '')
|
95
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
96
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
97
|
+
.downcase
|
98
|
+
.to_sym
|
99
|
+
end
|
76
100
|
end
|
data/simple_symbolize.gemspec
CHANGED
@@ -5,7 +5,7 @@ require_relative 'lib/simple_symbolize/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'simple_symbolize'
|
7
7
|
spec.version = SimpleSymbolize::VERSION
|
8
|
-
spec.authors = ['alexo']
|
8
|
+
spec.authors = ['alexo', 'Driver and Vehicle Licensing Agency (DVLA)']
|
9
9
|
spec.email = ['']
|
10
10
|
|
11
11
|
spec.summary = 'Turns Strings into Symbols.'
|
@@ -18,11 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.license = 'MIT'
|
19
19
|
spec.required_ruby_version = Gem::Requirement.new('>= 3.0')
|
20
20
|
|
21
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
-
|
23
21
|
spec.metadata['homepage_uri'] = spec.homepage
|
24
22
|
spec.metadata['source_code_uri'] = spec.homepage
|
25
|
-
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
26
23
|
|
27
24
|
# Specify which files should be added to the gem when it is released.
|
28
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -32,9 +29,4 @@ Gem::Specification.new do |spec|
|
|
32
29
|
spec.bindir = 'exe'
|
33
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
31
|
spec.require_paths = ['lib']
|
35
|
-
|
36
|
-
spec.add_development_dependency 'pry', '~> 0.14'
|
37
|
-
spec.add_development_dependency 'rake', '~> 13.0'
|
38
|
-
spec.add_development_dependency 'rspec', '~> 3.12'
|
39
|
-
spec.add_development_dependency 'rubocop', '~> 1.54'
|
40
32
|
end
|
metadata
CHANGED
@@ -1,71 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_symbolize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alexo
|
8
|
-
|
8
|
+
- Driver and Vehicle Licensing Agency (DVLA)
|
9
|
+
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: pry
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.14'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.14'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '13.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '13.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '3.12'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '3.12'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.54'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.54'
|
12
|
+
date: 2025-08-01 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
69
14
|
description: 'simple_symbolize will remove special characters from a String, replacing
|
70
15
|
whitespace with an underscore, down-casing and finally calling the #to_sym String
|
71
16
|
method. Configure this gem to your hearts content!'
|
@@ -88,7 +33,8 @@ files:
|
|
88
33
|
- bin/console
|
89
34
|
- bin/setup
|
90
35
|
- lib/simple_symbolize.rb
|
91
|
-
- lib/simple_symbolize/string.rb
|
36
|
+
- lib/simple_symbolize/core_ext/string/symbolize.rb
|
37
|
+
- lib/simple_symbolize/core_ext/symbol/symbolize.rb
|
92
38
|
- lib/simple_symbolize/translations.rb
|
93
39
|
- lib/simple_symbolize/version.rb
|
94
40
|
- simple_symbolize.gemspec
|
@@ -98,7 +44,7 @@ licenses:
|
|
98
44
|
metadata:
|
99
45
|
homepage_uri: https://github.com/dvla/simple-symbolize
|
100
46
|
source_code_uri: https://github.com/dvla/simple-symbolize
|
101
|
-
post_install_message:
|
47
|
+
post_install_message:
|
102
48
|
rdoc_options: []
|
103
49
|
require_paths:
|
104
50
|
- lib
|
@@ -114,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
60
|
version: '0'
|
115
61
|
requirements: []
|
116
62
|
rubygems_version: 3.2.15
|
117
|
-
signing_key:
|
63
|
+
signing_key:
|
118
64
|
specification_version: 4
|
119
65
|
summary: Turns Strings into Symbols.
|
120
66
|
test_files: []
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'simple_symbolize'
|
4
|
-
|
5
|
-
# Extends the String class by mixing in the symbolize module.
|
6
|
-
class String
|
7
|
-
# @example Symbolize a string using the String object method
|
8
|
-
# "hello world!".symbolize #=> :hello_world
|
9
|
-
def symbolize
|
10
|
-
SimpleSymbolize.symbolize(self)
|
11
|
-
end
|
12
|
-
|
13
|
-
# @example Turns a String into it's snake_case equivalent
|
14
|
-
# "helloWorld".to_snake_case => 'hello_word'
|
15
|
-
def to_snake_case
|
16
|
-
# rubocop:disable Style/RedundantSelf
|
17
|
-
self.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
18
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
19
|
-
.downcase
|
20
|
-
# rubocop:enable Style/RedundantSelf
|
21
|
-
end
|
22
|
-
end
|