Class: Natspec::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/natspec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(head, sections) ⇒ Document

Returns a new instance of Document.



10
11
12
13
14
15
# File 'lib/natspec.rb', line 10

def initialize( head, sections )
   @head      = head
   @sections = sections

   @storage, @functions = _parse_sections( @sections )
end

Instance Attribute Details

#functionsObject (readonly)

Returns the value of attribute functions.



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

def functions
  @functions
end

#headObject (readonly)

Returns the value of attribute head.



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

def head
  @head
end

#sectionsObject (readonly)

Returns the value of attribute sections.



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

def sections
  @sections
end

#storageObject (readonly)

Returns the value of attribute storage.



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

def storage
  @storage
end

Instance Method Details

#_parse_sections(sections) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/natspec.rb', line 17

def _parse_sections( sections )

  storage = {}
  functions = {}

  sections.each do |heading, lines|

    if (m=heading.match(/\Astorage[ ]+(.+)[ ]+(?<id>[_A-Za-z0-9]+)\z/))
       storage[ m[:id] ] = [heading,lines]
    elsif (m=heading.match(/\Afunction[ ]+(?<id>[_A-Za-z0-9]+)([ (]|\z)/))
       functions[ m[:id] ] = [heading,lines]
    else
      puts "!! ERROR - unsupported heading type in line >#{heading}<; sorry"
      exit 1
    end
  end

  [storage, functions]
end