everyday-cli-utils 0.3.0 → 0.4.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: b519a76138a2e3d8d4906235acf55c0579a7f11f
4
- data.tar.gz: c2d4e843d1be0a4c19c4b2b53b2e2b2da305724c
3
+ metadata.gz: 8afc8c7cdc6d4d3adffcc15723afa531d4961533
4
+ data.tar.gz: de9412ebd7b3965986e8fb66821ac94b3057a429
5
5
  SHA512:
6
- metadata.gz: ca5221853db3b28969056198aaae0a3ba235b561c813f023e17a61a6311f63ebd04ba2327722ef8b66aaea06bbedcf8816b5c7c008395317dbab2b593c44101a
7
- data.tar.gz: 76b6953166fc4afdd406905d56978f5a7776da41a71bd87e796eef676aeb583e992d72364be3495c3170668fe0ed72d8fabd4e7ac7f6a0180087d53fd3efab57
6
+ metadata.gz: 2ba0851f31eee49fa57b74dc5b7e5999a34ebfccd56ca9e8b3446452d8f93ae5ae8dbd1f4e2d5a4f42186df2ce44050f30da8d5d93cffb6f43e1feadd8cd6d8e
7
+ data.tar.gz: 656476dd69d7b17479d4aba60904a6d3685fac59461f73b9759a4929643e11fac61785a57f85c258b17a47950653b55953a0b2d775b90f6ace73519ba29d66c8
@@ -19,4 +19,8 @@ class String
19
19
  colors = 'black|red|green|yellow|blue|purple|cyan|white|none'
20
20
  (!(name =~ /format(_bold)?(_underline)?(?:_fg_(#{colors}))?(?:_bg_(#{colors}))?/).nil?) || old_respond_to?(method)
21
21
  end
22
+
23
+ def format_all
24
+ EverydayCliUtils::Format::format_all(self)
25
+ end
22
26
  end
@@ -103,5 +103,19 @@ module EverydayCliUtils
103
103
  def self::boldunderline(text, fgcolor = nil, bgcolor = nil)
104
104
  self::format(text, self::build_string(true, true, fgcolor, bgcolor))
105
105
  end
106
+
107
+ def self::format_all(text)
108
+ colors = 'bk|rd|gr|yw|bl|pu|cy|wh|no'
109
+ color_map = { 'bk' => :black, 'rd' => :red, 'gr' => :green, 'yw' => :yellow, 'bl' => :blue, 'pu' => :purple, 'cy' => :cyan, 'wh' => :white, 'no' => :none }
110
+ regex = /\{(.+?)\}\((bd)?(ul)?(?:f(#{colors}))?(?:b(#{colors}))?\)/
111
+ text.gsub(regex) { |m|
112
+ txt = $1
113
+ bold = !$2.nil?
114
+ underline = !$3.nil?
115
+ fg = $4.nil? ? nil : color_map[$4]
116
+ bg = $5.nil? ? nil : color_map[$5]
117
+ format(txt, build_string(bold, underline, fg, bg))
118
+ }
119
+ end
106
120
  end
107
121
  end
@@ -1,3 +1,3 @@
1
1
  module EverydayCliUtils
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -61,4 +61,10 @@ describe EverydayCliUtils::Format do
61
61
  str.respond_to?(:hi).should be_false
62
62
  expect { str.hi }.to raise_error(NameError)
63
63
  end
64
+
65
+ it 'allows shorthand for formatting in-string' do
66
+ str = 'abc {def}(bdulfywbgr) ghi {jkl}(ulfyw) mno'
67
+ expected = "abc #{'def'.format_bold_underline_fg_yellow_bg_green} ghi #{'jkl'.format_underline_fg_yellow} mno"
68
+ str.format_all.should eq expected
69
+ end
64
70
  end
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: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Henderson