everyday-cli-utils 1.2.0 → 1.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
  SHA1:
3
- metadata.gz: eab4ed95a5c1dc20cf4e4faa6202989b19a85d97
4
- data.tar.gz: 00c28312e37700149f707cd2a718c05e8331859a
3
+ metadata.gz: 6aaaed2712c0b90ca6ed889e79e62365f22212d8
4
+ data.tar.gz: 5a599eaf22c830354c9b23ccc50ac574d44e2d31
5
5
  SHA512:
6
- metadata.gz: aa9403aff6a4d6d30698ed1119b98cba40697a9519f6d31c18157d581fd6f0c6d99fcd13f7177a28a3036ac9fc573f8114a36acc01dca34a4596256313900ac4
7
- data.tar.gz: eec2dcca50851e200c609ef100cee89f982d5669d0434f700b2e927acca5e6fe401d17e56409282b6a51f7a69310fd26404f98ad948326c14653d32fa468020a
6
+ metadata.gz: 5c6fd0fa669e955f0070ea5332c1cc80c78a0d6d7d6dab07d1a0890fa4a996343aea11ad58d815b6eb23e751281824c8cdfe2c981aa2656614589042669d08c7
7
+ data.tar.gz: cd14ebdc8c59db60787338915eaf61f62b45b1ae0022c2cb0654b32b953edf756a64e9bd729fbea3fb25422458b0220c51024e4adbc6ea568498026abddf38fd
@@ -24,6 +24,10 @@ class String
24
24
  EverydayCliUtils::Format::format_all(self)
25
25
  end
26
26
 
27
+ def remove_format
28
+ EverydayCliUtils::Format::remove_format(self)
29
+ end
30
+
27
31
  def mycenter(len, char = ' ')
28
32
  EverydayCliUtils::Format::mycenter(self, len, char)
29
33
  end
@@ -119,6 +119,13 @@ module EverydayCliUtils
119
119
  }.gsub(regex2) { |_| format($1, color_profile_string($2.to_sym)) }
120
120
  end
121
121
 
122
+ def self::remove_format(text)
123
+ colors = 'bk|rd|gr|yw|bl|pu|cy|wh|no'
124
+ regex = /\{(.+?)\}\((bd)?(ul)?(?:f(#{colors}))?(?:b(#{colors}))?\)/
125
+ regex2 = /\{(.+?)\}\(:(.+?)\)/
126
+ text.gsub(regex, '\1').gsub(regex2, '\1') {}
127
+ end
128
+
122
129
  def self.mycenter(str, len, char = ' ')
123
130
  tlen = str.gsub(%r{\e\[.*?m}, '').length
124
131
  return str if tlen >= len
@@ -1,3 +1,3 @@
1
1
  module EverydayCliUtils
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -76,6 +76,20 @@ describe EverydayCliUtils::Format do
76
76
  str.format_all.should eq expected
77
77
  end
78
78
 
79
+ it 'allows removing shorthand for formatting in-string' do
80
+ str = 'abc {def}(bdulfywbgr) ghi {jkl}(ulfyw) mno'
81
+ expected = 'abc def ghi jkl mno'
82
+ str.remove_format.should eq expected
83
+ end
84
+
85
+ it 'allows removing color profile shorthand for formatting in-string' do
86
+ EverydayCliUtils::Format.color_profile(:p1, bold: true, underline: true, fgcolor: :yellow, bgcolor: :green)
87
+ EverydayCliUtils::Format.color_profile(:p2, underline: true, fgcolor: :yellow)
88
+ str = 'abc {def}(:p1) ghi {jkl}(:p2) mno'
89
+ expected = 'abc def ghi jkl mno'
90
+ str.remove_format.should eq expected
91
+ end
92
+
79
93
  it 'allows centering a formatted string' do
80
94
  str = 'abc'
81
95
  str2 = str.center(10)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everyday-cli-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Henderson