Sha256: d68551e9664e4ebbd0c43ebfc76f8323a1bf674f25b747360de83614a334750a

Contents?: true

Size: 891 Bytes

Versions: 11

Compression:

Stored size: 891 Bytes

Contents

require 'ripper'

module Rgot
  class ExampleParser < Ripper
    attr_accessor :examples
    def initialize(code)
      super
      @examples = []
      @in_def = false
      @has_output = false
      @output = ""
    end

    def on_def(method, args, body)
      @examples << ExampleOutput.new(method.to_sym, @output.dup)
      @output.clear
      @has_output = false
      @in_def = false
    end

    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

    def on_kw(a)
      case a
      when "def"
        @in_def = true
      when "end"
        @in_def = false
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rgot-1.1.0 lib/rgot/example_parser.rb
rgot-0.2.0 lib/rgot/example_parser.rb
rgot-0.1.5 lib/rgot/example_parser.rb
rgot-0.1.4 lib/rgot/example_parser.rb
rgot-0.1.3 lib/rgot/example_parser.rb
rgot-0.1.2 lib/rgot/example_parser.rb
rgot-0.1.1 lib/rgot/example_parser.rb
rgot-0.1.0 lib/rgot/example_parser.rb
rgot-0.0.5 lib/rgot/example_parser.rb
rgot-0.0.4 lib/rgot/example_parser.rb
rgot-0.0.3 lib/rgot/example_parser.rb