Class: Elisp2any::Section

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/elisp2any/section.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(heading:, blocks:, sections:) ⇒ Section

Returns a new instance of Section.



38
39
40
41
42
# File 'lib/elisp2any/section.rb', line 38

def initialize(heading:, blocks:, sections:)
  @heading = heading
  @blocks = blocks
  @sections = sections
end

Instance Attribute Details

#blocksObject (readonly) Also known as: paragraphs

Returns the value of attribute blocks.



8
9
10
# File 'lib/elisp2any/section.rb', line 8

def blocks
  @blocks
end

#headingObject (readonly)

Returns the value of attribute heading.



8
9
10
# File 'lib/elisp2any/section.rb', line 8

def heading
  @heading
end

#sectionsObject (readonly)

Returns the value of attribute sections.



8
9
10
# File 'lib/elisp2any/section.rb', line 8

def sections
  @sections
end

Class Method Details

.scan(scanner) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/elisp2any/section.rb', line 13

def self.scan(scanner)
  heading = Heading.scan(scanner) or return
  heading.content = Text.scan(heading.content)
  Blanklines.scan(scanner) # optional
  blocks = []
  while (blo = Paragraph.scan(scanner) || Codeblock.scan(scanner))
    blocks << blo
    Blanklines.scan(scanner) # optional
  end
  pos = scanner.pos
  sections = []
  while (section = scan(scanner))
    if section.level == heading.level + 1
      sections << section
      pos = scanner.pos
    elsif section.level >= heading.level + 2
      raise Error, "too demoted heading"
    else
      scanner.pos = pos
      break
    end
  end
  new(heading:, blocks:, sections:)
end