string_dot_gradient 0.1.7 → 0.1.8

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: 73df78b09463b558f80961be83861765cf026a674b0be3ab76213f1b1f5c8aed
4
- data.tar.gz: 6e561b3415470f06426aab38fc0d97a51289cf82a9ef68bab9b14646d33983fb
3
+ metadata.gz: 7f734ad48d80c57969e3fb4598f5a89fafdb35b30c2b5dddbc1bbbf1a835a829
4
+ data.tar.gz: 80c268d0c7754047bf1040d1ade34a3e9652180441ca3cbf23a0d67f8873d531
5
5
  SHA512:
6
- metadata.gz: 5772433cb33f8756a01efb8a7b2723624ff8874270a6205e9c51f12ba29113cf95fb3a6a924003e416da3c5e4aa676144297df7b7ab6c1c05b4f455fc991fd83
7
- data.tar.gz: a35256dc944c405e5652d0cab8792c18f89f2592e0cf1bf918e690f5312b53863ad9048140eeb271d238fd17689f6675510ffc5239737b7d77e09f57f0a239e8
6
+ metadata.gz: 0102ffe6acc5355cc7d29dea013439eb245fc5ec11415eea6cc91f1025a6128f639120b74d29d0dec44ebf085f73d41411d6027480b4270dc832d17e5e353cf7
7
+ data.tar.gz: d0d2c157c03af2a8688fcba1ade8d5177e0d8656512b9293a26672faf9dddb492a530e409df9e6ffa5f32f75f05d0c6c041ac13f4cc0a75c4067b4fc59bf9144
@@ -50,8 +50,10 @@ class String
50
50
  all_rgbs = flatten_colours.map!(&method(:hex_to_rgb))
51
51
  block_given = block_given?
52
52
 
53
- r, g, b = all_rgbs[0]
54
- r2, g2, b2 = all_rgbs[1]
53
+ # r, g, b => starting r, g, b
54
+ # r2, g2, b2 => stopping r, g, b
55
+ r, g, b = *all_rgbs[0]
56
+ r2, g2, b2 = *all_rgbs[1]
55
57
  rotate = all_rgbs.length > 2
56
58
 
57
59
  init = bg ? 48 : 38
@@ -62,53 +64,45 @@ class String
62
64
 
63
65
  len = c.length
64
66
  n_variable = exclude_spaces ? c.delete("\t\s".freeze).length : len
65
- n_variable = 1 if n_variable == 0
67
+ n_variable -= 1
68
+ n_variable = 1 if n_variable < 1
66
69
 
67
- r_op = r_val = r_max = r_min = nil
68
- g_op = g_val = g_max = g_min = nil
69
- b_op = b_val = b_max = b_min = nil
70
-
71
- r_comp_op = r_comp_val = nil
72
- g_comp_op = g_comp_val = nil
73
- b_comp_op = b_comp_val = nil
70
+ # colour operator, colour value
71
+ r_op = r_val = nil
72
+ g_op = g_val = nil
73
+ b_op = b_val = nil
74
74
 
75
75
  if r2 > r
76
- r_op, r_val, r_max, r_min = :+, r2.fdiv(n_variable), r2, r
77
- r_comp_op, r_comp_val = :<=, r_max
76
+ r_op, r_val = :+, r2.-(r).fdiv(n_variable)
78
77
  elsif r2 < r
79
- r_op, r_val, r_max, r_min = :-, r.fdiv(n_variable), r, r2
80
- r_comp_op, r_comp_val = :>=, r_min
78
+ r_op, r_val = :-, r.-(r2).fdiv(n_variable)
81
79
  end
82
80
 
83
81
  if g2 > g
84
- g_op, g_val, g_max, g_min = :+, g2.fdiv(n_variable), g2, g
85
- g_comp_op, g_comp_val = :<=, g_max
82
+ g_op, g_val = :+, g2.-(g).fdiv(n_variable)
86
83
  elsif g2 < g
87
- g_op, g_val, g_max, g_min = :-, g.fdiv(n_variable), g, g2
88
- g_comp_op, g_comp_val = :>=, g_min
84
+ g_op, g_val = :-, g.-(g2).fdiv(n_variable)
89
85
  end
90
86
 
91
87
  if b2 > b
92
- b_op, b_val, b_max, b_min = :+, b2.fdiv(n_variable), b2, b
93
- b_comp_op, b_comp_val = :<=, b_max
88
+ b_op, b_val = :+, b2.-(b).fdiv(n_variable)
94
89
  elsif b2 < b
95
- b_op, b_val, b_max, b_min = :-, b.fdiv(n_variable), b, b2
96
- b_comp_op, b_comp_val = :>=, b_min
90
+ b_op, b_val = :-, b.-(b2).fdiv(n_variable)
97
91
  end
98
92
 
99
93
  # To avoid the value getting adding | subtracted from the initial character
100
- _r = _r.send(r_op, r_val * -1) if r_comp_op && _r.send(r_comp_op, r_comp_val)
101
- _g = _g.send(g_op, g_val * -1) if g_comp_op && _g.send(g_comp_op, g_comp_val)
102
- _b = _b.send(b_op, b_val * -1) if b_comp_op && _b.send(b_comp_op, b_comp_val)
94
+ _r = _r.send(r_op, r_val * -1) if r_op
95
+ _g = _g.send(g_op, g_val * -1) if g_op
96
+ _b = _b.send(b_op, b_val * -1) if b_op
103
97
 
104
98
  i = -1
105
99
  while (i += 1) < len
106
100
  _c = c[i]
107
101
 
108
102
  if !exclude_spaces || (exclude_spaces && !(_c == ?\s.freeze || _c == ?\t.freeze))
109
- _r = _r.send(r_op, r_val) if r_comp_op && _r.send(r_comp_op, r_comp_val)
110
- _g = _g.send(g_op, g_val) if g_comp_op && _g.send(g_comp_op, g_comp_val)
111
- _b = _b.send(b_op, b_val) if b_comp_op && _b.send(b_comp_op, b_comp_val)
103
+ _r = _r.send(r_op, r_val) if r_op
104
+ _g = _g.send(g_op, g_val) if g_op
105
+ _b = _b.send(b_op, b_val) if b_op
112
106
  end
113
107
 
114
108
  r_to_i = _r.to_i
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StringDotGradient
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.8"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_dot_gradient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
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-10 00:00:00.000000000 Z
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An itty-bitty extension that adds gradient method to String class that
14
14
  supports any hex colour, for Linux | Unix terminals only