Class: Ankit::StylableText
- Inherits:
-
Object
- Object
- Ankit::StylableText
- Defined in:
- lib/ankit/challenge.rb
Class Method Summary collapse
Instance Method Summary collapse
- #decorated(type) ⇒ Object
-
#initialize(text) ⇒ StylableText
constructor
A new instance of StylableText.
Constructor Details
#initialize(text) ⇒ StylableText
Returns a new instance of StylableText.
36 |
# File 'lib/ankit/challenge.rb', line 36 def initialize(text); @text = text; end |
Class Method Details
.styled_text(text, type) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ankit/challenge.rb', line 13 def self.styled_text(text, type) case type when :hidden text.gsub(/\w/, "*") when :failed HighLine.color(text, HighLine::RED_STYLE) when :warn HighLine.color(text, HighLine::YELLOW_STYLE) when :passed HighLine.color(text, HighLine::GREEN_STYLE) when :pending HighLine.color(text, HighLine::DARK) when :correct HighLine.color(text, HighLine::GREEN_STYLE) when :wrong HighLine.color(text, HighLine::RED_STYLE) when :fyi HighLine.color(text, HighLine::DARK) else raise end end |
Instance Method Details
#decorated(type) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/ankit/challenge.rb', line 38 def decorated(type) raise decorated = @text.gsub(/\[(.*?)\]/) { |t| self.class.styled_text($1, type) } decorated != @text ? decorated : self.class.styled_text(@text, type) end |