Class: Rgot::ExampleParser

Inherits:
Ripper
  • Object
show all
Defined in:
lib/rgot/example_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ ExampleParser

Returns a new instance of ExampleParser.



6
7
8
9
10
11
12
# File 'lib/rgot/example_parser.rb', line 6

def initialize(code)
  super
  @examples = []
  @in_def = false
  @has_output = false
  @output = ""
end

Instance Attribute Details

#examplesObject

Returns the value of attribute examples.



5
6
7
# File 'lib/rgot/example_parser.rb', line 5

def examples
  @examples
end

Instance Method Details

#on_comment(a) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rgot/example_parser.rb', line 21

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) ⇒ Object



14
15
16
17
18
19
# File 'lib/rgot/example_parser.rb', line 14

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) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/rgot/example_parser.rb', line 37

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