Module: Crayon::StringBuilder
- Included in:
- Crayon
- Defined in:
- lib/crayon/string_builder.rb
Instance Method Summary collapse
- #background_string ⇒ Object
- #foreground_string ⇒ Object
- #formatting_string ⇒ Object
- #handle_color(lead, color) ⇒ Object
- #has_color? ⇒ Boolean
- #prepare_string(string) ⇒ Object
Instance Method Details
#background_string ⇒ Object
20 21 22 |
# File 'lib/crayon/string_builder.rb', line 20 def background_string handle_color(4, @background) end |
#foreground_string ⇒ Object
16 17 18 |
# File 'lib/crayon/string_builder.rb', line 16 def foreground_string handle_color(3, @foreground) end |
#formatting_string ⇒ Object
24 25 26 27 |
# File 'lib/crayon/string_builder.rb', line 24 def formatting_string return "" if @formatting.empty? @formatting.map{|format| "\e[#{FORMATS[format]}m"}.join("") end |
#handle_color(lead, color) ⇒ Object
29 30 31 32 |
# File 'lib/crayon/string_builder.rb', line 29 def handle_color(lead, color) return "" unless color "\e[#{lead}#{COLORS[color]}m" end |
#has_color? ⇒ Boolean
12 13 14 |
# File 'lib/crayon/string_builder.rb', line 12 def has_color? @foreground || @background || @formatting.any? end |
#prepare_string(string) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/crayon/string_builder.rb', line 3 def prepare_string(string) [ foreground_string, background_string, formatting_string, string, (TERMINATION_STRING if has_color?) ].compact.join("") end |