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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e65f856a5767b2902d8676cc7497d8a759cfcce1caf231929c7671d7d4410dc
4
- data.tar.gz: 68f58d2e0aa05cb117eb502da389315c5beb66d26cb3d8c82897b931a7207dd6
3
+ metadata.gz: 3d3884abc820fe0e165c6bd457b9fdb6ad5a65daa2e0a50228d26d66cfd81e83
4
+ data.tar.gz: d2aa74283174640d6f80b68237804311bb80542405421aca50cc0e54f8b32aaf
5
5
  SHA512:
6
- metadata.gz: 667ec6cecb555d77bc0a9e31f106d8fa3ce4fd86bd12a6ff37c7c9c03ed9b1d4c6187746cbc8a2e2e3215e90a8a1c748a25b94d37a59970303a3c28c6760aa97
7
- data.tar.gz: fa0f08dd87d24724cb3567a6348bb46e81a7803ef9b069dc15498312404a14ed55e6b19da19da6f24e935f81938dbdb9a18fdd8f87bca0cb75df124c863eebfb
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
- def gradient(*arg_colours, bg: false)
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
- _r = _r.send(*r_meth) unless _r > r_max || _r < r_min
69
- _g = _g.send(*g_meth) unless _g > g_max || _g < g_min
70
- _b = _b.send(*b_meth) unless _b > b_max || _b < b_min
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StringDotGradient
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_dot_gradient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourav Goswami