Module: As3gettext::As3Parser

Defined in:
lib/as3gettext/as3_parser.rb

Class Method Summary collapse

Class Method Details

.parse(file, targets = []) ⇒ Object

:nodoc:



7
8
9
10
# File 'lib/as3gettext/as3_parser.rb', line 7

def parse(file, targets = [])  # :nodoc:
  lines = IO.readlines(file)
  parse_lines(file, lines, targets)
end

.parse_lines(file_name, lines, targets) ⇒ Object

:nodoc:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/as3gettext/as3_parser.rb', line 12

def parse_lines(file_name, lines, targets)  # :nodoc:
  begin
    lines.each_with_index do |line, i|
      if m = (line.match(/_\('([^']+)'\)/) || line.match(/_\("([^"]+)"\)/) )
        name = m[1].gsub(/\n/, '\n')
        if t = targets.detect{|a| a[0] == name}
          t[1] << ', ' + file_name + ":" + (i+1).to_s
        else
          targets << [name, file_name + ":" + (i+1).to_s]
        end
      end
    end
  rescue
    $stderr.print "\n\nError: #{$!.inspect} "
    $stderr.print " in #{file_name}:#{tk.line_no}\n\t #{lines[tk.line_no - 1]}" if tk
    $stderr.print "\n"
    exit
  end
  targets
end

.target?(file) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/as3gettext/as3_parser.rb', line 33

def target?(file)
  ['.as', '.mxml'].include? File.extname(file)
end