Class: Ollama::Utils::ColorizeTexts
- Inherits:
-
Object
- Object
- Ollama::Utils::ColorizeTexts
- Defined in:
- lib/ollama/utils/colorize_texts.rb
Instance Method Summary collapse
-
#initialize(*texts) ⇒ ColorizeTexts
constructor
A new instance of ColorizeTexts.
- #to_s ⇒ Object
Methods included from Width
Methods included from Math
#convert_to_vector, #cosine_similarity, #norm
Constructor Details
#initialize(*texts) ⇒ ColorizeTexts
Returns a new instance of ColorizeTexts.
6 7 8 9 |
# File 'lib/ollama/utils/colorize_texts.rb', line 6 def initialize(*texts) texts = texts.map(&:to_a) @texts = Array(texts.flatten) end |
Instance Method Details
#to_s ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ollama/utils/colorize_texts.rb', line 11 def to_s result = +'' @texts.each_with_index do |t, i| color = colors[(t.hash ^ i.hash) % colors.size] wrap(t, percentage: 90).each_line { |l| result << on_color(color) { color(text_color(color)) { l } } } result << "\n##{bold{t.size.to_s}} \n\n" end result end |