Class: Coradoc::CoreModel::IncludeOptions

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/core_model/include_options.rb

Overview

Typed options for an include directive, parsed once at construction.

Each asciidoctor selector (tags / lines / leveloffset / indent / encoding) gets one typed attribute. Selectors downstream operate on the typed form, never re-parsing the raw string (DRY).

tags          Array<String>   ["body"], [] when unspecified
tags_wildcard Boolean         true for tags=*
tags_inverted Boolean         true for tags=**
lines_spec    String?         raw "1..2;5;7..8" — parsed by Lines selector
leveloffset   IncludeLevelOffset?
indent        Integer?        0 = strip, N = re-indent, nil = passthrough
file_encoding String?         passed through to resolver for File.read

Instance Attribute Summary

Attributes inherited from Base

#element_attributes, #id, #metadata_entries, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#accept, #attr, #flat_text, #metadata, #semantically_equivalent?, #set_attr, #set_metadata

Class Method Details

.from_hash(attrs) ⇒ IncludeOptions

Build from a flat hash of asciidoctor-style key/value strings. Whitespace around keys and values is trimmed (SPEC 6.3).

Parameters:

  • attrs (Hash{String=>String})

    e.g. “leveloffset”=>“+2”

Returns:



48
49
50
# File 'lib/coradoc/core_model/include_options.rb', line 48

def self.from_hash(attrs)
  new(build_args(attrs))
end

Instance Method Details

#conflict_resolved_to_lines?Boolean

True when both selectors were specified (lines wins).

Returns:

  • (Boolean)


39
40
41
# File 'lib/coradoc/core_model/include_options.rb', line 39

def conflict_resolved_to_lines?
  lines? && tags?
end

#lines?Boolean

Whether the lines selector is in effect. Tags are ignored when lines is set — matches asciidoctor precedence (SPEC 3.5).

Returns:

  • (Boolean)


29
30
31
# File 'lib/coradoc/core_model/include_options.rb', line 29

def lines?
  !lines_spec.nil? && !lines_spec.strip.empty?
end

#tags?Boolean

Whether any tag selector is in effect.

Returns:

  • (Boolean)


34
35
36
# File 'lib/coradoc/core_model/include_options.rb', line 34

def tags?
  tags_wildcard || tags_inverted || !tags.empty?
end