Class: DocBlocksExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/ex-doc-include.rb

Instance Method Summary collapse

Constructor Details

#initializeDocBlocksExtractor

Returns a new instance of DocBlocksExtractor.



5
6
7
8
# File 'lib/ex-doc-include.rb', line 5

def initialize()
  @count_leading_spaces = 0
  @active_block = false
end

Instance Method Details

#_block_close?(toks) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ex-doc-include.rb', line 36

def _block_close?(toks)
  return (@active_block and toks.slice(-1) == '*/')
end

#_block_open?(toks) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ex-doc-include.rb', line 24

def _block_open?(toks)
  return (not @active_block and toks.slice(..1) == ['/*!', '#ex-doc'])
end

#_block_role(toks) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/ex-doc-include.rb', line 28

def _block_role(toks)
  if toks.length >= 3
    return toks[2]
  end
  return ''

end

#_process_as_block_line(l) ⇒ Object



14
15
16
17
18
# File 'lib/ex-doc-include.rb', line 14

def _process_as_block_line(l)

  min_col = [@count_leading_spaces, l.length].min
  return l.slice( min_col..)
end

#_store_block_info(l) ⇒ Object



10
11
12
# File 'lib/ex-doc-include.rb', line 10

def _store_block_info(l)
  @count_leading_spaces = l.length - l.lstrip.length
end

#_tokenize(l) ⇒ Object



20
21
22
# File 'lib/ex-doc-include.rb', line 20

def _tokenize(l)
  return l.split.reject { |c| c.empty? }.each { |t| t.strip }
end

#process_line(l) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ex-doc-include.rb', line 40

def process_line(l)
  toks = _tokenize(l)
  if _block_open?(toks)
    toggle_active_block
    _store_block_info(l)
    return _block_role(toks)
  
  elsif _block_close?(toks)
    toggle_active_block
    l = l.rstrip.slice(...-2).rstrip
    return _process_as_block_line(l)
  
  elsif @active_block
    return  _process_as_block_line(l) 
  end
 
end

#to_procObject



58
# File 'lib/ex-doc-include.rb', line 58

def to_proc = method(:process_line).to_proc

#toggle_active_blockObject



60
61
62
63
# File 'lib/ex-doc-include.rb', line 60

def toggle_active_block
  @active_block = !@active_block
  return @active_block
end