Module: Coradoc::IncludeSelectors::Lines
- Defined in:
- lib/coradoc/include_selectors/lines.rb
Overview
Line-range selection. Parses asciidoctor-style specs:
N single line
A..B inclusive range
A..B;C;D..E multiple, semicolon-separated
Out-of-bounds clamps gracefully (SPEC 3.4). One-based indexing (asciidoctor convention).
Constant Summary collapse
- SPEC_PART =
%r{ \A (?<start>\d+) (?:\.\.(?<finish>\d+))? \z }x.freeze
Class Method Summary collapse
Class Method Details
.call(text, options:) ⇒ String
24 25 26 27 28 29 30 31 32 |
# File 'lib/coradoc/include_selectors/lines.rb', line 24 def self.call(text, options:) return text unless .lines? ranges = parse_spec(.lines_spec, max: text.lines.length) return '' if ranges.empty? indices = ranges.flat_map { |start, finish| (start..finish).to_a }.uniq.sort text.lines.values_at(*indices.map { |i| i - 1 }).join end |