Class: Asciidoctor::IncludeExt::LinenoLinesSelector
- Inherits:
-
Object
- Object
- Asciidoctor::IncludeExt::LinenoLinesSelector
- Defined in:
- lib/asciidoctor/include_ext/lineno_lines_selector.rb
Overview
Instance of this class can be used only once, as a predicate to filter a single include directive.
Lines selector that selects lines of the content to be included based on the specified ranges of line numbers.
Instance Attribute Summary collapse
-
#first_included_lineno ⇒ Integer?
readonly
1-based line number of the first included line, or `nil` if none.
Class Method Summary collapse
-
.handles?(_, attributes) ⇒ Boolean
`true` if the attributes hash contains a key `“lines”`.
Instance Method Summary collapse
-
#include?(_, line_num) ⇒ Boolean
Returns `true` if the given line should be included, `false` otherwise.
-
#initialize(_, attributes) ⇒ LinenoLinesSelector
constructor
A new instance of LinenoLinesSelector.
-
#to_proc ⇒ Proc
#include? method as a Proc.
Constructor Details
#initialize(_, attributes) ⇒ LinenoLinesSelector
Returns a new instance of LinenoLinesSelector.
34 35 36 37 |
# File 'lib/asciidoctor/include_ext/lineno_lines_selector.rb', line 34 def initialize(_, attributes, **) @ranges = parse_attribute(attributes['lines']) @first_included_lineno = @ranges.last.first unless @ranges.empty? end |
Instance Attribute Details
#first_included_lineno ⇒ Integer? (readonly)
Returns 1-based line number of the first included line, or `nil` if none.
23 24 25 |
# File 'lib/asciidoctor/include_ext/lineno_lines_selector.rb', line 23 def first_included_lineno @first_included_lineno end |
Class Method Details
.handles?(_, attributes) ⇒ Boolean
Returns `true` if the attributes hash contains a key `“lines”`.
28 29 30 |
# File 'lib/asciidoctor/include_ext/lineno_lines_selector.rb', line 28 def self.handles?(_, attributes) attributes.key? 'lines' end |
Instance Method Details
#include?(_, line_num) ⇒ Boolean
This method modifies state of this object. It's supposed to be called successively with each line of the content being included. See example.
Returns `true` if the given line should be included, `false` otherwise.
47 48 49 50 51 52 53 |
# File 'lib/asciidoctor/include_ext/lineno_lines_selector.rb', line 47 def include?(_, line_num) return false if @ranges.empty? ranges = @ranges ranges.pop while !ranges.empty? && ranges.last.last < line_num ranges.last.cover?(line_num) if !ranges.empty? end |
#to_proc ⇒ Proc
Returns #include? method as a Proc.
56 57 58 |
# File 'lib/asciidoctor/include_ext/lineno_lines_selector.rb', line 56 def to_proc method(:include?).to_proc end |