class Rgot::ExampleParser

Attributes

examples[RW]

@dynamic examples, examples=

Public Class Methods

new(code) click to toggle source
Calls superclass method
# File lib/rgot/example_parser.rb, line 11
def initialize(code)
  super
  @examples = []
  @in_def = false
  @has_output = false
  @output = "".dup
end

Public Instance Methods

on_comment(a) click to toggle source
# File lib/rgot/example_parser.rb, line 26
def on_comment(a)
  if @in_def
    if @has_output
      @output << a.sub(/\A#\s*/, '')
    else
      if /#\s*Output:\s*(.*?\n)/ =~ a
        text = $1
        if 0 < text.length || text[0] != "\n"
          @output << text
        end
        @has_output = true
      end
    end
  end
end
on_def(method, args, body) click to toggle source
# File lib/rgot/example_parser.rb, line 19
def on_def(method, args, body)
  @examples << ExampleOutput.new(method.to_sym, @output.dup)
  @output.clear
  @has_output = false
  @in_def = false
end
on_kw(a) click to toggle source
# File lib/rgot/example_parser.rb, line 42
def on_kw(a)
  case a
  when "def"
    @in_def = true
  when "end"
    @in_def = false
  end
end