Module: Opmac2html::TextCutter

Included in:
Converter
Defined in:
lib/opmac2html/text_cutter.rb

Overview

Mixin providing text partitioning

Instance Method Summary collapse

Instance Method Details

#cut_at(separator) ⇒ Object



4
5
6
7
8
# File 'lib/opmac2html/text_cutter.rb', line 4

def cut_at(separator)
  part = @input.partition separator
  @input = part[2]
  part[0]
end

#cut_at_match_with_start(text, beg_sep, end_sep) ⇒ Object



16
17
18
19
20
21
# File 'lib/opmac2html/text_cutter.rb', line 16

def cut_at_match_with_start(text, beg_sep, end_sep)
  return ['', '', ''] if text.empty?
  index = matching_separator_index text, beg_sep, end_sep
  el = end_sep.length
  [text[0...index], text[index, el] || '', text[index + el..-1] || '']
end

#cut_at_matching(text, beg_sep, end_sep) ⇒ Object



23
24
25
26
27
28
# File 'lib/opmac2html/text_cutter.rb', line 23

def cut_at_matching(text, beg_sep, end_sep)
  return ['', ''] if text.empty?
  index = matching_separator_index text, beg_sep, end_sep
  bi, bl, el = text.index(beg_sep), beg_sep.length, end_sep.length
  [text[bi + bl...index], text[index + el..-1] || '']
end

#cut_at_with_sep(separator) ⇒ Object



10
11
12
13
14
# File 'lib/opmac2html/text_cutter.rb', line 10

def cut_at_with_sep(separator)
  part = @input.partition separator
  @input = part[1] + part[2]
  part[0]
end