niceties 0.1.0 → 0.2.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/.gitignore +2 -0
- data/README.md +38 -0
- data/lib/niceties/array.rb +8 -0
- data/lib/niceties/float.rb +8 -0
- data/lib/niceties/integer.rb +8 -0
- data/lib/niceties/object.rb +4 -1
- data/lib/niceties/version.rb +1 -1
- data/lib/niceties.rb +4 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5303d182f90f15c71f74382af7747c3f59db95b71869c76558607575f16096d8
|
4
|
+
data.tar.gz: 587bb532dadde01c08f8ec563c0032adaa596d9bc7ee35ebc049735917ba0919
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f64b16ad027af13f3564e9f163c374f69ab68389fd1017b7e52254b0ae415541e504d7449c03ce860e113ed704a8f37aaba65aef1d8f83b56cfb6be73e2bd0e
|
7
|
+
data.tar.gz: 4fd2cd8131b9c76525abd11b7f986e1ec7f507efec8855a1c2215eda59a8e33cbaf584158c94aef2493da4d7cd457d3e1f8673c44c719f58b340e633a15a57e9
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -21,6 +21,44 @@ You should be able to drop Niceties into your app and feel like it’s always be
|
|
21
21
|
|
22
22
|
---
|
23
23
|
|
24
|
+
## What's on the Menu
|
25
|
+
|
26
|
+
Niceties provides the following methods so far:
|
27
|
+
|
28
|
+
### Object
|
29
|
+
|
30
|
+
```rb
|
31
|
+
# Object.try_each
|
32
|
+
@user.try_each(:full_name, :nickname, :username) # instead of @user&.full_name || @user&.nickname || @user&.username
|
33
|
+
|
34
|
+
# Object.coalesce
|
35
|
+
@user.coalesce(:full_name, :nickname, "Valued Customer") # instead of @user&.full_name || @user&.nickname || "Valued Customer"
|
36
|
+
|
37
|
+
# Object.not_a?
|
38
|
+
@user.not_a? Widget # instead of !@user.is_a? Widget
|
39
|
+
```
|
40
|
+
|
41
|
+
### Array
|
42
|
+
|
43
|
+
```rb
|
44
|
+
# Array.tidy
|
45
|
+
["", nil, 4].tidy => [4] # instead of ["", nil, 4].select { it.present? }
|
46
|
+
```
|
47
|
+
|
48
|
+
### Numerics (Integer and Float)
|
49
|
+
|
50
|
+
```rb
|
51
|
+
# Integer.percent_of
|
52
|
+
25.percent_of(200) => 50 # instead of (200 / 100.0) * 25
|
53
|
+
|
54
|
+
# Float.percent_of
|
55
|
+
16.6.percent_of(1000) => 166 # instead of (1000 / 100.0) * 16.6
|
56
|
+
```
|
57
|
+
|
58
|
+
More methods will be coming soon and contributions are very much welcomed!
|
59
|
+
|
60
|
+
---
|
61
|
+
|
24
62
|
## 🫂 Contributing
|
25
63
|
|
26
64
|
Niceties is open to anyone with an idea that makes Ruby or Rails feel better to use.
|
data/lib/niceties/object.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Niceties for the Object class
|
1
4
|
class Object
|
2
5
|
def not_a?(klass)
|
3
6
|
!is_a?(klass)
|
4
7
|
end
|
5
8
|
|
6
|
-
def
|
9
|
+
def try_each(*methods)
|
7
10
|
methods.each do |method|
|
8
11
|
result = try(method)
|
9
12
|
return result unless result.nil?
|
data/lib/niceties/version.rb
CHANGED
data/lib/niceties.rb
CHANGED
@@ -4,6 +4,10 @@ require "active_support/core_ext/object/try"
|
|
4
4
|
require "active_support/core_ext/object/blank"
|
5
5
|
require_relative "niceties/version"
|
6
6
|
require_relative "niceties/object"
|
7
|
+
require_relative "niceties/array"
|
8
|
+
require_relative "niceties/integer"
|
9
|
+
require_relative "niceties/float"
|
7
10
|
|
11
|
+
# See individual class files for implementations
|
8
12
|
module Niceties
|
9
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niceties
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Dawson
|
@@ -23,8 +23,8 @@ dependencies:
|
|
23
23
|
- - ">="
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: '6.0'
|
26
|
-
description: Niceties is a
|
27
|
-
|
26
|
+
description: Niceties is a curated set of small, ergonomic and expressive methods
|
27
|
+
for Ruby and Rails.
|
28
28
|
email:
|
29
29
|
- email@carldaws.com
|
30
30
|
executables: []
|
@@ -40,6 +40,9 @@ files:
|
|
40
40
|
- bin/console
|
41
41
|
- bin/setup
|
42
42
|
- lib/niceties.rb
|
43
|
+
- lib/niceties/array.rb
|
44
|
+
- lib/niceties/float.rb
|
45
|
+
- lib/niceties/integer.rb
|
43
46
|
- lib/niceties/object.rb
|
44
47
|
- lib/niceties/version.rb
|
45
48
|
- sig/niceties.rbs
|