fun_with_string_colors 0.0.3 → 0.0.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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjZhNjlhZDM0MmFkYTg1NjhmOGU3MmI0NjcyMDVlNTY0ZjlmZWRjMg==
4
+ MjE1MjhiZTZlNDg2MGNmOWQxNGIzYTA2ZTcwOWM2ODZkM2Q0NGZjNw==
5
5
  data.tar.gz: !binary |-
6
- OWNjZDhiZWQ2MWFjYmY1MDk2YmJjOGVkMmYxOWEzNDE2ZmRkOTIyZQ==
6
+ YWRiMDU5MzI1OWYzZjNlOTJlODI2NjcwNGNkYWI5YmY0NjY1NTk4Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDI5NzJiNmU2M2E2ZTgyMWU2NGY4ZTFhMzE4YzY1OWZkNTk2OGU1ZDkzOTc5
10
- MmJjZmQyNjg0NzljYjNkNWZhZGQzMDJhMWI2NGE1ZWQ0OGM5ZDIzM2M0NzE2
11
- M2JmNTMzMTFiNmYwMmJkMjE1OWJkMTk4MDFmZjhhNjc0MGRlNWQ=
9
+ YmNlNTQyYjA1ZDc2NTAxODZlN2EzNWMzMDI2NTUwN2MyODVkNTk2ZTFiM2Ix
10
+ YTc2ZjA2MzY5YWRkNzM4MjRlYTNmNzg3ODBiOTYyZTU4ZGE1MGRlODc4MTAz
11
+ MmExYjg4ZDdmZGMwYTg2ZmZiZjgxMGRlMDM5Y2I1MzRlMGUxNTY=
12
12
  data.tar.gz: !binary |-
13
- Njg3OGM2ZmZlZmRiOGI3Nzc5OTU1ZDc4ZTI4MDhlZTYwMDExYzVjNWI5MjQ3
14
- OTFhYmQxODJmY2Y1NmQ2MTQxMGQ2YzE0M2FhY2Y5MWU1YmIwNDQ4MDE4MzUz
15
- ZDI1NzZmN2Y2M2Y2MjcwMTJiYmZhMTAwNjBlOWMwZmJkMjNiNDU=
13
+ NTAzNTQ2MjBiZWQ3MzU2ODcyNDFlOGM0YWE3ZDM3MDgzOTQyMzE0MGY5MWIz
14
+ ZTc1M2RmYWZmZTU3Y2M4ZTZjNGIzYzEwMWUwNWMzMDlhNzI1MWNkNDk1ZTdi
15
+ ODU2NjA4MGUxOGJhMTJlYmRkNDkzNzkxN2QwMWZhYjc3ZWI1NTY=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -50,33 +50,15 @@ module FunWith
50
50
  highlight_regex = colors.first.is_a?(Regexp) ? colors.shift : nil
51
51
 
52
52
  rval = self.dup
53
- prependers = []
54
- terminations = []
55
-
56
- for color in colors
57
- case color
58
- when :reset, :unpaint
59
- regex = /\e\[\d+m/
60
- rval = rval.gsub( regex, '' )
61
- prependers = []
62
- terminations = []
63
- when Symbol
64
- if ANSI_COLORS[color]
65
- prependers << "\e[#{ANSI_COLORS[color]}m"
66
- terminations << (ANSI_COLOR_TERMINATORS[color] || ANSI_COLOR_TERMINATORS[:color])
67
- end
68
- when /^\d+$/, Integer # you can give numbers/number strings directly
69
- prependers << "\e[#{ANSI_COLORS[color] || color}m"
70
- terminations << (ANSI_COLOR_TERMINATORS[color.to_i] || ANSI_COLOR_TERMINATORS[:color])
71
- end
72
- end
53
+ prependers, terminations, reset = self.fwsc_map_color_args_to_prepend_and_terminate( colors )
54
+ rval = rval.gsub( /\e\[\d+m/, '' ) if reset
73
55
 
74
56
  if highlight_regex.nil?
75
57
  #puts "prependers #{prependers.inspect}"
76
58
  #puts "terminations #{terminations.inspect}"
77
- prependers.join + rval + terminations.join
59
+ prependers.uniq.join + rval + terminations.uniq.join
78
60
  else
79
- rval.gsub( /(#{highlight_regex})/, prependers.join + "\\1" + terminations.join )
61
+ rval.gsub( /(#{highlight_regex})/, prependers.uniq.join + "\\1" + terminations.uniq.join )
80
62
  end
81
63
  else
82
64
  self.dup # Since it returns a duplicate of the original when in paint mode, this is more consistent behavior
@@ -86,6 +68,32 @@ module FunWith
86
68
  def paint?
87
69
  self.class.colorize?
88
70
  end
71
+
72
+ protected
73
+ def fwsc_map_color_args_to_prepend_and_terminate( colors )
74
+ prependers = []
75
+ terminations = []
76
+ reset = false
77
+
78
+ for color in colors
79
+ case color
80
+ when :reset, :unpaint
81
+ prependers = []
82
+ terminations = []
83
+ reset = true
84
+ when Symbol
85
+ if ANSI_COLORS[color]
86
+ prependers << "\e[#{ANSI_COLORS[color]}m"
87
+ terminations << (ANSI_COLOR_TERMINATORS[color] || ANSI_COLOR_TERMINATORS[:color])
88
+ end
89
+ when /^\d+$/, Integer # you can give numbers/number strings directly
90
+ prependers << "\e[#{ANSI_COLORS[color] || color}m"
91
+ terminations << (ANSI_COLOR_TERMINATORS[color.to_i] || ANSI_COLOR_TERMINATORS[:color])
92
+ end
93
+ end
94
+
95
+ [prependers, terminations, reset]
96
+ end
89
97
  end
90
98
  end
91
99
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fun_with_string_colors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryce Anderson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-18 00:00:00.000000000 Z
11
+ date: 2014-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fun_with_testing