Class: Documentrix::Utils::ColorizeTexts
- Inherits:
-
Object
- Object
- Documentrix::Utils::ColorizeTexts
- Includes:
- Math, Kramdown::ANSI::Width, Term::ANSIColor
- Defined in:
- lib/documentrix/utils/colorize_texts.rb
Instance Method Summary collapse
-
#initialize(*texts) ⇒ Documentrix::::ColorizeTexts
constructor
Initializes a new instance of Documentrix::::ColorizeTexts.
-
#to_s ⇒ String
Returns a string representation of the object, including all texts content, colored differently and their sizes.
Methods included from Math
#convert_to_vector, #cosine_similarity, #norm
Constructor Details
#initialize(*texts) ⇒ Documentrix::::ColorizeTexts
Initializes a new instance of Documentrix::::ColorizeTexts
14 15 16 17 |
# File 'lib/documentrix/utils/colorize_texts.rb', line 14 def initialize(*texts) texts = texts.map(&:to_a) @texts = Array(texts.flatten) end |
Instance Method Details
#to_s ⇒ String
Returns a string representation of the object, including all texts content, colored differently and their sizes.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/documentrix/utils/colorize_texts.rb', line 23 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 |