conveniences 0.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 +7 -0
- data/LICENSE +21 -0
- data/lib/conveniences/blank.rb +41 -0
- data/lib/conveniences/hash_ext.rb +23 -0
- data/lib/conveniences/string_ext.rb +32 -0
- data/lib/conveniences/version.rb +5 -0
- data/lib/conveniences.rb +6 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: '085e3dace81fbd227f3acdefec3a28fa2c0218f85234b521f8f60958c0400caa'
|
|
4
|
+
data.tar.gz: efff66cfc12b65f9bf4ca4823ce4facdec7e016d1b3a8e1dc30494dc36f3ec12
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 004b1ef5f237941a3b6d72de4783728a9e88a6992096040f318f48caa249f87a99c3083ca344f64935563c85d3bc03517ab03a151e9dcd66f09eb28203aebf04
|
|
7
|
+
data.tar.gz: de24c53cc080fe66d6b7acde31b5b2faac072a37b34b7dbbc82243b5e31e7af567798740a81ba3a77631c3b8f54bbfc1e4a6aaa64a4514dc69c7172bf3bf72cc
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Scott Wright
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Object
|
|
4
|
+
def blank?
|
|
5
|
+
respond_to?(:empty?) ? !!empty? : !self
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def present?
|
|
9
|
+
!blank?
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class NilClass
|
|
14
|
+
def blank?
|
|
15
|
+
true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class FalseClass
|
|
20
|
+
def blank?
|
|
21
|
+
true
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class TrueClass
|
|
26
|
+
def blank?
|
|
27
|
+
false
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class Numeric
|
|
32
|
+
def blank?
|
|
33
|
+
false
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class String
|
|
38
|
+
def blank?
|
|
39
|
+
match?(/\A[[:space:]]*\z/)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Hash
|
|
4
|
+
def deep_symbolize_keys
|
|
5
|
+
each_with_object({}) do |(key, value), result|
|
|
6
|
+
result[key.respond_to?(:to_sym) ? key.to_sym : key] = Conveniences.deep_symbolize(value)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def deep_symbolize_keys!
|
|
11
|
+
replace(deep_symbolize_keys)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
module Conveniences
|
|
16
|
+
def self.deep_symbolize(value)
|
|
17
|
+
case value
|
|
18
|
+
when Hash then value.deep_symbolize_keys
|
|
19
|
+
when Array then value.map { |v| deep_symbolize(v) }
|
|
20
|
+
else value
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class String
|
|
4
|
+
def pluralize
|
|
5
|
+
case self
|
|
6
|
+
when /(s|x|z|ch|sh)\z/i then "#{self}es"
|
|
7
|
+
when /[^aeiou]y\z/i then "#{self[0...-1]}ies"
|
|
8
|
+
else "#{self}s"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def camelize
|
|
13
|
+
split("/").map do |part|
|
|
14
|
+
part.split("_").map { |word| capitalize_word(word) }.join
|
|
15
|
+
end.join("::")
|
|
16
|
+
end
|
|
17
|
+
alias_method :camelcase, :camelize
|
|
18
|
+
|
|
19
|
+
def titleize
|
|
20
|
+
tr("_", " ").split(" ").map { |word| capitalize_word(word) }.join(" ")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def constantize
|
|
24
|
+
split("::").reject(&:empty?).inject(Object) { |scope, name| scope.const_get(name) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def capitalize_word(word)
|
|
30
|
+
word.empty? ? word : word[0].upcase + word[1..]
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/conveniences.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: conveniences
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Scott Wright
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: minitest
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '5.0'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '5.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: standard
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '1.0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rake
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '13.0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '13.0'
|
|
54
|
+
description: Homegrown blank?/present?, deep_symbolize_keys, and String inflection
|
|
55
|
+
(pluralize/camelize/titleize/constantize) core extensions for non-Rails projects.
|
|
56
|
+
email:
|
|
57
|
+
- scott@wrightzone.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- LICENSE
|
|
63
|
+
- lib/conveniences.rb
|
|
64
|
+
- lib/conveniences/blank.rb
|
|
65
|
+
- lib/conveniences/hash_ext.rb
|
|
66
|
+
- lib/conveniences/string_ext.rb
|
|
67
|
+
- lib/conveniences/version.rb
|
|
68
|
+
homepage: https://codeberg.org/jswright61/conveniences
|
|
69
|
+
licenses:
|
|
70
|
+
- MIT
|
|
71
|
+
metadata: {}
|
|
72
|
+
rdoc_options: []
|
|
73
|
+
require_paths:
|
|
74
|
+
- lib
|
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '3.1'
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
requirements: []
|
|
86
|
+
rubygems_version: 4.0.16
|
|
87
|
+
specification_version: 4
|
|
88
|
+
summary: A handful of ActiveSupport-style core extensions, with no Rails required
|
|
89
|
+
test_files: []
|