string_dot_gradient 0.1.2 → 0.1.3
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/lib/string_dot_gradient/gradient.rb +32 -6
- data/lib/string_dot_gradient/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d3884abc820fe0e165c6bd457b9fdb6ad5a65daa2e0a50228d26d66cfd81e83
|
4
|
+
data.tar.gz: d2aa74283174640d6f80b68237804311bb80542405421aca50cc0e54f8b32aaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f1b712b76b2fd010b4995967f57178c1949e4ded080e02c2e95e06848a8b8b729ac4e56c1d43fb698180163cd401979c3820f6659f9b80d4777c6c37092fdeb
|
7
|
+
data.tar.gz: 1bb3c798b4ab1c1d4814dac2470e90d0d79836aade65429e31b428fbb29a36260a60ff3e6a90c31e91a0ee2d8580bacb1c17fb215057a4e9da219e365fd82e6d
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class String
|
2
2
|
##
|
3
|
-
# = gradient(*arg_colours, bg: false) # => string or nil
|
3
|
+
# = gradient(*arg_colours, bg: false, exclude_spaces: true) # => string or nil
|
4
4
|
#
|
5
|
-
# Prettifies your string by adding gradient colours
|
5
|
+
# Prettifies your string by adding gradient colours.
|
6
6
|
#
|
7
7
|
# This method accept a lot of colours. For example:
|
8
8
|
#
|
@@ -29,7 +29,18 @@ class String
|
|
29
29
|
#
|
30
30
|
# Adding the option bg will change the background colour, but will keep the foreground colour
|
31
31
|
# defined in the terminal settings.
|
32
|
-
|
32
|
+
#
|
33
|
+
# The option exclude_spaces, is expected to set either true or false.
|
34
|
+
# By default it's set to true.
|
35
|
+
# Enabling this option will not waste colours on white-spaces.
|
36
|
+
# White spaces only include: \s, \t
|
37
|
+
#
|
38
|
+
# Please do note that \u0000 and \r in the middle of the string will not be
|
39
|
+
# counted as a white space, but as a character instead.
|
40
|
+
# This is because \r wipes out the previous characters, and using \u0000 in
|
41
|
+
# a string is uncommon, and developers are requested to delete
|
42
|
+
# \u0000 from string if such situations arise.
|
43
|
+
def gradient(*arg_colours, bg: false, exclude_spaces: true)
|
33
44
|
colours, line_length = [], -1
|
34
45
|
temp = ''
|
35
46
|
flatten_colours = arg_colours.flatten
|
@@ -65,9 +76,24 @@ class String
|
|
65
76
|
|
66
77
|
i = -1
|
67
78
|
while (i += 1) < n
|
68
|
-
|
69
|
-
|
70
|
-
|
79
|
+
if exclude_spaces
|
80
|
+
_c = c[i]
|
81
|
+
|
82
|
+
if !(_c == ?\s.freeze || _c == ?\t.freeze)
|
83
|
+
_r = _r.send(*r_meth) unless _r > r_max || _r < r_min
|
84
|
+
_g = _g.send(*g_meth) unless _g > g_max || _g < g_min
|
85
|
+
_b = _b.send(*b_meth) unless _b > b_max || _b < b_min
|
86
|
+
end
|
87
|
+
else
|
88
|
+
# We also have duplication above,
|
89
|
+
# But we are not going to remove this code unless
|
90
|
+
# we find some efficient solution. Using a proc or method
|
91
|
+
# for setting these values and calling that is a way
|
92
|
+
# to make code slower.
|
93
|
+
_r = _r.send(*r_meth) unless _r > r_max || _r < r_min
|
94
|
+
_g = _g.send(*g_meth) unless _g > g_max || _g < g_min
|
95
|
+
_b = _b.send(*b_meth) unless _b > b_max || _b < b_min
|
96
|
+
end
|
71
97
|
|
72
98
|
r_to_i = _r.to_i
|
73
99
|
g_to_i = _g.to_i
|