Class: Elisp2any::Heading

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, level, content) ⇒ Heading

TODO: delete node. Use kwargs.



36
37
38
39
40
# File 'lib/elisp2any/heading.rb', line 36

def initialize(node, level, content) # :nodoc:
  @node = node
  @level = level
  @content = content
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/elisp2any/heading.rb', line 7

def content
  @content
end

#levelObject (readonly)

Returns the value of attribute level.



6
7
8
# File 'lib/elisp2any/heading.rb', line 6

def level
  @level
end

Class Method Details

.scan(scanner) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/elisp2any/heading.rb', line 9

def self.scan(scanner)
  pos = scanner.pos
  comment = Comment.scan(scanner) or return
  unless comment.colons >= 3
    scanner.pos = pos
    return
  end
  new(:TODO, comment.colons - 3,
      comment.content # do not scan as text at this point
     )
end

Instance Method Details

#code?Boolean

:nodoc:



57
58
59
# File 'lib/elisp2any/heading.rb', line 57

def code? # :nodoc:
  @level == 1 && @content == 'Code:'
end

#commentary?Boolean

:nodoc:



53
54
55
# File 'lib/elisp2any/heading.rb', line 53

def commentary? # :nodoc:
  @level == 1 && @content == 'Commentary:'
end

#deconstruct_keys(*keys) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/elisp2any/heading.rb', line 21

def deconstruct_keys(*keys)
  result = {}
  keys => [keys]
  keys.each do |key|
    case key
    in :level
      result[:level] = @level
    in :content
      result[:content] = @content
    end
  end
  result
end

#final_nameObject

:nodoc:



61
62
63
# File 'lib/elisp2any/heading.rb', line 61

def final_name # :nodoc:
  @content.match(/\A(?<name>.+?)\.el ends here\Z/)[:name]
end

#name_and_synopsisObject

Returns nil if failed



43
44
45
46
47
48
49
50
51
# File 'lib/elisp2any/heading.rb', line 43

def name_and_synopsis # :nodoc:
  scanner = StringScanner.new(@content)
  name = scanner.scan_until(/\.el/) or return
  name = name[nil...-3] or return
  scanner.skip(/\s+---\s+/) or return
  scanner.skip(/(?<synopsis>.+?)(:?\s+-\*- .+? -\*-)?\Z/) or return
  synopsis = scanner[:synopsis]
  return name, synopsis
end