Class: ExportStrings::ByLex

Inherits:
Object
  • Object
show all
Defined in:
lib/export_strings/by_lex.rb

Class Method Summary collapse

Class Method Details

.execute(rb_text) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/export_strings/by_lex.rb', line 6

def execute(rb_text)
  @string_flag = false
  @embexpr_flag = false
  @str = ''
  results = []
  Ripper.lex(rb_text).each do |ary_code|
    code_type = ary_code[1]
    code_content = ary_code[2]
    if embexpr_flag(code_type)
      @str << code_content
      next
    end

    if string_flag(code_type)
      next if code_type == :on_tstring_beg || code_type == :on_heredoc_beg

      @str << code_content
    elsif !string_flag(code_type) && !@str.empty?
      results.push @str
      @str = ''
    end
  end
  results
end