Module: RegexUtils

Included in:
StringHound
Defined in:
lib/regex_utils.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/regex_utils.rb', line 3

def self.included(base)
  base.class_eval do

    def parse_for_strings(line)
      line.scan(/["'][\w\s#\{\}]*["']/)
    end

    def is_erb_txt(line)
      !!line.match(/<%=/).nil? && line.match(/(<%|%>)/)
    end

    def is_javascript(line)
      !!line.match(/(\$j|\$z|function)/)
    end

    def find_printed_erb(line)
      line.match(/<%=.*?(\n|%>)/)
    end

    def inline_strings(line)
      if @inline && line.match(/^[\s]*(TEXT|CONTENT)/)
        @inline = nil
      elsif @inline || match = line.match(/(<<-TEXT|<<-CONTENT)[\s]*/)
        @inline = true
        match.nil? ? line : match.post_match
      end
    end

    def find_variables(content)
      content.scan(/#\{(\w*)\}/)
    end

  end
end