Class: PactBroker::Client::ColorizeNotices
- Inherits:
-
Object
- Object
- PactBroker::Client::ColorizeNotices
- Defined in:
- lib/pact_broker/client/colorize_notices.rb
Class Method Summary collapse
- .call(notices) ⇒ Object
- .color_for_type(type) ⇒ Object
- .color_for_url(text, uris) ⇒ Object
- .colorized_message(notice) ⇒ Object
Class Method Details
.call(notices) ⇒ Object
6 7 8 9 10 |
# File 'lib/pact_broker/client/colorize_notices.rb', line 6 def self.call(notices) notices.collect do | notice | (notice) end end |
.color_for_type(type) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/pact_broker/client/colorize_notices.rb', line 32 def self.color_for_type(type) case type when "warning", "prompt" then :yellow when "error", "danger" then :red when "success" then :green else nil end end |
.color_for_url(text, uris) ⇒ Object
26 27 28 29 30 |
# File 'lib/pact_broker/client/colorize_notices.rb', line 26 def self.color_for_url(text, uris) uris.inject(text) do | new_text, uri | new_text.gsub(uri, ::Term::ANSIColor.magenta(uri)) end end |
.colorized_message(notice) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pact_broker/client/colorize_notices.rb', line 12 def self.(notice) color = color_for_type(notice.type) uri_strings = ::URI.extract(notice.text, %w(http https)) if color && uri_strings.any? color_for_url(::Term::ANSIColor.color(color, notice.text || ''), uri_strings) elsif color ::Term::ANSIColor.color(color, notice.text || '') elsif uri_strings.any? color_for_url(notice.text, uri_strings) else notice.text end end |