Class: ClosureCompilerParser

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/closure_compiler/closure_compiler_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ ClosureCompilerParser

Returns a new instance of ClosureCompilerParser.


3
4
5
6
7
8
9
10
# File 'lib/tasks/closure_compiler/closure_compiler_parser.rb', line 3

def initialize(dir)
  @dir = dir
 
  # TODO: Tidy!
  if (RUBY_PLATFORM =~ /mswin32/)
    @dir = @dir.gsub('/', '\\')
  end 
end

Instance Method Details

#parse_result(detail) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tasks/closure_compiler/closure_compiler_parser.rb', line 12

def parse_result(detail)
  summary_line = detail.grep( /\d+\s+error.*,\s+\d+\s+warning.*/ )[0]
  
  if summary_line.nil?
    # error
    error_info = (detail + "\nUnknown Error!").to_a[0].strip
    return :error, 'Error', error_info
  end
  
  if summary_line =~ /([1-9]+)\d*\s+error/
    num_failures = $1
    error_info = detail.grep(/ ERROR - /)[0].strip
    return :failure, num_failures + ' Errors', strip_dir(error_info)
  end
 
  if summary_line =~ /([1-9]+)\d*\s+warning/
    num_failures = $1
    error_info = detail.grep(/ WARNING - /)[0].strip
    return :warning, num_failures + ' Warnings', strip_dir(error_info)
  end
  
  return :success, 'All files compiled successfully', ''
end

#strip_dir(text) ⇒ Object


36
37
38
39
40
41
42
43
44
# File 'lib/tasks/closure_compiler/closure_compiler_parser.rb', line 36

def strip_dir(text)

  # Move to function/class w/ win32 related code
  if (text[0, @dir.length] == @dir)
    text = text[(@dir.length + 1)..-1]
  end    
  
  text
end