Module: Mdlint::TextWidth
- Defined in:
- lib/mdlint/text_width.rb,
sig/internal.rbs
Class Method Summary collapse
Class Method Details
.measure(text) ⇒ Integer
6 7 8 |
# File 'lib/mdlint/text_width.rb', line 6 def measure(text) text.to_s.each_codepoint.sum { |codepoint| wide?(codepoint) ? 2 : 1 } end |
.take(text, maximum) ⇒ String
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mdlint/text_width.rb', line 10 def take(text, maximum) width = 0 result = +"" text.each_char do |character| character_width = measure(character) break if width + character_width > maximum result << character width += character_width end result end |