Class: CoffeeScriptParser

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/coffeescript/coffeescript_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ CoffeeScriptParser

Returns a new instance of CoffeeScriptParser.



3
4
5
6
7
8
9
10
# File 'lib/tasks/coffeescript/coffeescript_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
# File 'lib/tasks/coffeescript/coffeescript_parser.rb', line 12

def parse_result(detail)
  if (detail.strip == '')
    return :success, 'All files compiled', ''
  end
  
  summary_line = detail.grep( /^In .*/ )[0]

  if summary_line.nil?
    # error
    error_info = (detail + "\nUnknown Error!").to_a[0].strip
    return :error, 'Error', error_info
  end
  
  return :failure, 'Failed to compile', strip_dir(summary_line[3..-1].strip)
end

#strip_dir(text) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/tasks/coffeescript/coffeescript_parser.rb', line 28

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    
  
end