Class: Dokaz::Parser

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Parser

Returns a new instance of Parser.



25
26
27
# File 'lib/dokaz/parser.rb', line 25

def initialize(path)
  @path = path
end

Instance Method Details

#parseObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dokaz/parser.rb', line 29

def parse
  res = []
  ln = 0
  scanner = StringScanner.new(File.read(@path))
  loop do
    text = scanner.scan_until(/\n```ruby\n/)
    break unless text
    
    ln += text.count("\n")
    code = scanner.scan_until(/\n```\n/)
    if !code
      res << Block.new(scanner.rest, ln, @path)
      break
    end
    res << Block.new(code.sub(/```\Z/, ''), ln, @path)
    ln += code.count("\n")
  end

  res
end