string_dot_gradient 0.1.3 → 0.1.4
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 +37 -14
- data/lib/string_dot_gradient/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baaf12a84ca6429f8d3a85cf87e208dcdf1900e5b8fdb2193b6bdb6802b5e3be
|
4
|
+
data.tar.gz: e3bbba2902b6cc3dd9b0c37fb1cd3e983a5c3d0ca979478eccdf077a0d6d4e1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60d6427e5b4cb12ce92542cfb8f180ecf5eefe80d82528f16718660a4b24d6afdc56c94448eac709af6870f757cdb788a4a9d427fc89fd60557abcee7ffdb7cf
|
7
|
+
data.tar.gz: 0cdf009682bc2506cb83c1e65138737e724096fa6db8a7991d999e26a0899a1177d56fd361efdca724890c827e40487e1add6957746aa74617832cc98187561e
|
@@ -49,7 +49,6 @@ class String
|
|
49
49
|
raise ArgumentError, "Given argument for colour is neither a String nor an Integer" if flatten_colours.any? { |x| !(x.is_a?(String) || x.is_a?(Integer)) }
|
50
50
|
|
51
51
|
all_rgbs = flatten_colours.map!(&method(:hex_to_rgb))
|
52
|
-
|
53
52
|
block_given = block_given?
|
54
53
|
|
55
54
|
r, g, b = all_rgbs[0]
|
@@ -62,13 +61,37 @@ class String
|
|
62
61
|
_r, _g, _b = r, g, b
|
63
62
|
n = c.length
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
r_op = r_val = r_max = r_min = nil
|
65
|
+
g_op = g_val = g_max = g_min = nil
|
66
|
+
b_op = b_val = b_max = b_min = nil
|
67
|
+
|
68
|
+
r_comp_op = r_comp_val = nil
|
69
|
+
g_comp_op = g_comp_val = nil
|
70
|
+
b_comp_op = b_comp_val = nil
|
71
|
+
|
72
|
+
if r2 > r
|
73
|
+
r_op, r_val, r_max, r_min = :+, r2.fdiv(n), r2, r
|
74
|
+
r_comp_op, r_comp_val = :<=, r_max
|
75
|
+
elsif r2 < r
|
76
|
+
r_op, r_val, r_max, r_min = :-, r.fdiv(n), r, r2
|
77
|
+
r_comp_op, r_comp_val = :>=, r_min
|
78
|
+
end
|
68
79
|
|
69
|
-
|
70
|
-
|
71
|
-
|
80
|
+
if g2 > g
|
81
|
+
g_op, g_val, g_max, g_min = :+, g2.fdiv(n), g2, g
|
82
|
+
g_comp_op, g_comp_val = :<=, g_max
|
83
|
+
elsif g2 < g
|
84
|
+
g_op, g_val, g_max, g_min = :-, g.fdiv(n), g, g2
|
85
|
+
g_comp_op, g_comp_val = :>=, g_min
|
86
|
+
end
|
87
|
+
|
88
|
+
if b2 > b
|
89
|
+
b_op, b_val, b_max, b_min = :+, b2.fdiv(n), b2, b
|
90
|
+
b_comp_op, b_comp_val = :<=, b_max
|
91
|
+
elsif b2 < b
|
92
|
+
b_op, b_val, b_max, b_min = :-, b.fdiv(n), b, b2
|
93
|
+
b_comp_op, b_comp_val = :>=, b_min
|
94
|
+
end
|
72
95
|
|
73
96
|
if line_length != n || rotate
|
74
97
|
line_length = n
|
@@ -80,9 +103,9 @@ class String
|
|
80
103
|
_c = c[i]
|
81
104
|
|
82
105
|
if !(_c == ?\s.freeze || _c == ?\t.freeze)
|
83
|
-
_r = _r.send(
|
84
|
-
_g = _g.send(
|
85
|
-
_b = _b.send(
|
106
|
+
_r = _r.send(r_op, r_val) if r_comp_op && _r.send(r_comp_op, r_comp_val)
|
107
|
+
_g = _g.send(g_op, g_val) if g_comp_op && _g.send(g_comp_op, g_comp_val)
|
108
|
+
_b = _b.send(b_op, b_val) if b_comp_op && _b.send(b_comp_op, b_comp_val)
|
86
109
|
end
|
87
110
|
else
|
88
111
|
# We also have duplication above,
|
@@ -90,9 +113,9 @@ class String
|
|
90
113
|
# we find some efficient solution. Using a proc or method
|
91
114
|
# for setting these values and calling that is a way
|
92
115
|
# to make code slower.
|
93
|
-
_r = _r.send(
|
94
|
-
_g = _g.send(
|
95
|
-
_b = _b.send(
|
116
|
+
_r = _r.send(r_op, r_val) if r_comp_op && _r.send(r_comp_op, r_comp_val)
|
117
|
+
_g = _g.send(g_op, g_val) if g_comp_op && _g.send(g_comp_op, g_comp_val)
|
118
|
+
_b = _b.send(b_op, b_val) if b_comp_op && _b.send(b_comp_op, b_comp_val)
|
96
119
|
end
|
97
120
|
|
98
121
|
r_to_i = _r.to_i
|
@@ -160,7 +183,7 @@ class String
|
|
160
183
|
elsif clen == 6
|
161
184
|
colour.chars.each_slice(2).map { |x| x.join.to_i(16) }
|
162
185
|
else
|
163
|
-
sli = clen > 6 ? 'too long' : clen < 3 ? 'too short' : 'invalid'
|
186
|
+
sli = clen > 6 ? 'too long'.freeze : clen < 3 ? 'too short'.freeze : 'invalid'.freeze
|
164
187
|
raise ArgumentError, "Invalid Hex Colour ##{colour} (length #{sli})"
|
165
188
|
end
|
166
189
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string_dot_gradient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sourav Goswami
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: An itty-bitty extension that adds gradient method to String class
|
14
|
-
Linux terminals
|
13
|
+
description: An itty-bitty extension that adds gradient method to String class that
|
14
|
+
supports any hex colour, for Linux | Unix terminals only
|
15
15
|
email:
|
16
16
|
- souravgoswami@protonmail.com
|
17
17
|
executables: []
|
@@ -33,7 +33,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
33
|
requirements:
|
34
34
|
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 2.
|
36
|
+
version: 2.0.0
|
37
37
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
@@ -43,6 +43,6 @@ requirements: []
|
|
43
43
|
rubygems_version: 3.1.4
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
|
-
summary: An itty-bitty extension that adds gradient method to String class
|
47
|
-
terminals
|
46
|
+
summary: An itty-bitty extension that adds gradient method to String class that supports
|
47
|
+
any hex colour, for Linux | Unix terminals only
|
48
48
|
test_files: []
|