string_dot_gradient 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 888e756d71707ea2545d43cf8a3fdc38ac9a390570fe7b9e52271c89e7af3d7d
4
- data.tar.gz: fc1bf3010fca21e26c7ee07504ad2e76dd66affe2eff5acd6b316ebf2805a243
3
+ metadata.gz: d6fa81c2c57dbe1b9712438b587127627a24f23e7583b1892328412ebc14031a
4
+ data.tar.gz: 2960add227d5e2c678f693da5a6c84269045b286b1d3c37f8426eb66f776f6e0
5
5
  SHA512:
6
- metadata.gz: c9fce9010dba35978ef9b93e5336911f534b6d37c8635817240414a86411317f32626a6a50c0a52ef8bab7f27f12a7912fbaec572fa200a7b2011c858d8c5c0d
7
- data.tar.gz: 9cbf19d2ef2361f1d2bd6cd2ec39ea3e96264617bf5ba0a216c542bc4c401da58a72927095b360a204c0040c6e84d2688328002b0601e628b4eca5e6d9cd2157
6
+ metadata.gz: 63ffc5173183586621b0b98550651b4049875464aa39aa97f5b926e479cfad1b72ca4f63fb4c959a051a7d9552b1f8bfd5b94454318709986784e1b406ed7e33
7
+ data.tar.gz: 443780070aabb205c759966136b725cd3d7d2ca4e7f1cf2208407d1553db7e95ce6712fbddba594d5e12b218f8dbd10f48c9a5f1a10481d83e97b2bd7f820aad
@@ -183,6 +183,76 @@ class String
183
183
  block_given ? nil : temp
184
184
  end
185
185
 
186
+ ##
187
+ # = multi_gradient(*n_arg_colours, bg: false, exclude_spaces: true, bold: false, blink: false) # => string or nil
188
+ #
189
+ # Accepts n number of colours. Example:
190
+ # 'Hello world this is multi_gradient()'.multi_gradient('3eb', '55f', 'f55', 'fa0')
191
+ #
192
+ # In this example, multi_gradient() paints the string with 4 colours in one line.
193
+ #
194
+ # It Splits up a string with the Calls String#gradient() with the given number of colours
195
+ # So each call to multi_gradient() involves many calls to String#gradient().
196
+ # Hence it's slower than String#gradient()
197
+ def multi_gradient(*colours,
198
+ exclude_spaces: true,
199
+ bg: false,
200
+ bold: false,
201
+ italic: false,
202
+ underline: false,
203
+ blink: false,
204
+ strikethrough: false,
205
+ double_underline: false,
206
+ overline: false
207
+ )
208
+
209
+ len = colours.length
210
+ raise ArgumentError, "Minimum two colours are required, given #{len}" if len < 2
211
+
212
+ div = len - 1
213
+ div_1 = div - 1
214
+ ret = ''
215
+
216
+ params = {
217
+ exclude_spaces: exclude_spaces,
218
+ bg: bg,
219
+ bold: bold,
220
+ italic: italic,
221
+ underline: underline,
222
+ blink: blink,
223
+ strikethrough: strikethrough,
224
+ double_underline: double_underline,
225
+ overline: overline
226
+ }
227
+
228
+ each_line { |l|
229
+ _len = l.length
230
+
231
+ len, c = _len.fdiv(div).round, colours.dup
232
+ counter, i, j = -1, -1, 0
233
+ ch = ''
234
+
235
+ while x = l[i += 1] do
236
+ counter += 1
237
+
238
+ # colour % len == 0 is very slow approach
239
+ if counter == len && j < div_1
240
+ counter, j = 0, j + 1
241
+ ret << ch.gradient(c[0], c[1], **params)
242
+
243
+ c.rotate!
244
+ ch.clear
245
+ end
246
+
247
+ ch << x
248
+ end
249
+
250
+ ret << ch.gradient(c[0], c[1], **params)
251
+ }
252
+
253
+ ret
254
+ end
255
+
186
256
  private
187
257
  def hex_to_rgb(hex)
188
258
  # Duplicate colour, even if colour is nil
@@ -201,8 +271,7 @@ class String
201
271
  oor.include?(x) ? "\e[1;31m#{x}\e[0m" : x
202
272
  }.join
203
273
 
204
- puts "Hex Colour ##{invalids} is Out of Range"
205
- raise ArgumentError
274
+ raise ArgumentError, "\e[0mHex Colour \e[1m##{invalids} is Out of Range\e[0m"
206
275
  end
207
276
 
208
277
  clen = colour.length
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StringDotGradient
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
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.2.0
4
+ version: 0.3.0
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-15 00:00:00.000000000 Z
11
+ date: 2021-04-01 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 terminals
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  requirements: []
43
- rubygems_version: 3.1.4
43
+ rubygems_version: 3.2.13
44
44
  signing_key:
45
45
  specification_version: 4
46
46
  summary: An itty-bitty extension that adds "gradient" method to String class that