Class: Dokaz::Parser
- Inherits:
-
Object
- Object
- Dokaz::Parser
- Defined in:
- lib/dokaz/parser.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
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
#parse ⇒ Object
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 |