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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d3884abc820fe0e165c6bd457b9fdb6ad5a65daa2e0a50228d26d66cfd81e83
4
- data.tar.gz: d2aa74283174640d6f80b68237804311bb80542405421aca50cc0e54f8b32aaf
3
+ metadata.gz: baaf12a84ca6429f8d3a85cf87e208dcdf1900e5b8fdb2193b6bdb6802b5e3be
4
+ data.tar.gz: e3bbba2902b6cc3dd9b0c37fb1cd3e983a5c3d0ca979478eccdf077a0d6d4e1c
5
5
  SHA512:
6
- metadata.gz: 6f1b712b76b2fd010b4995967f57178c1949e4ded080e02c2e95e06848a8b8b729ac4e56c1d43fb698180163cd401979c3820f6659f9b80d4777c6c37092fdeb
7
- data.tar.gz: 1bb3c798b4ab1c1d4814dac2470e90d0d79836aade65429e31b428fbb29a36260a60ff3e6a90c31e91a0ee2d8580bacb1c17fb215057a4e9da219e365fd82e6d
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
- r_max, r_min = r > r2 ? [r, r2] : [r2, r]
66
- g_max, g_min = g > g2 ? [g, g2] : [g2, g]
67
- b_max, b_min = b > b2 ? [b, b2] : [b2, b]
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
- r_meth = r == r2 ? :itself : r2 > r ? [:+, r2.fdiv(n)] : [:-, r.fdiv(n)]
70
- g_meth = g == g2 ? :itself : g2 > g ? [:+, g2.fdiv(n)] : [:-, g.fdiv(n)]
71
- b_meth = b == b2 ? :itself : b2 > b ? [:+, b2.fdiv(n)] : [:-, b.fdiv(n)]
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(*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
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(*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
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StringDotGradient
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  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.3
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-08 00:00:00.000000000 Z
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, for
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.2.0
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, for Linux
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: []