Module: RubyProgress::StringExtensions

Included in:
String
Defined in:
lib/ruby-progress/ripple.rb

Overview

String extensions for color support

Instance Method Summary collapse

Instance Method Details

#normalize_typeObject



74
75
76
77
78
79
80
# File 'lib/ruby-progress/ripple.rb', line 74

def normalize_type
  spinner_type = :classic
  INDICATORS.each do |spinner, _v|
    spinner_type = spinner if spinner =~ /^#{chars.join('.*?')}/i
  end
  spinner_type
end

#rainbow(index = 0) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/ruby-progress/ripple.rb', line 65

def rainbow(index = 0)
  chars = self.chars
  colored_chars = chars.map.with_index do |char, idx|
    color = COLORS.values[(idx + index) % COLORS.size]
    "#{color}#{char}#{COLORS['reset']}"
  end
  colored_chars.join
end