Class: NetLinx::CompilerResult

Inherits:
Object
  • Object
show all
Defined in:
lib/netlinx/compiler_result.rb

Overview

Contains info pertaining to a job run through the compiler.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ CompilerResult

Returns a new instance of CompilerResult.

Parameters:

  • kwargs (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • :stream (String)

    The raw stream of text returned by the compiler.

  • :compiler_target_files (Array<String>)

    See Compilable interface.

  • :compiler_include_paths (Array<String>)

    See Compilable interface.

  • :compiler_module_paths (Array<String>)

    See Compilable interface.

  • :compiler_library_paths (Array<String>)

    See Compilable interface.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/netlinx/compiler_result.rb', line 27

def initialize(**kwargs)
  @stream   = kwargs.fetch :stream, ''
  
  @compiler_target_files  = kwargs.fetch :compiler_target_files,  []
  @compiler_include_paths = kwargs.fetch :compiler_include_paths, []
  @compiler_module_paths  = kwargs.fetch :compiler_module_paths,  []
  @compiler_library_paths = kwargs.fetch :compiler_library_paths, []      
  
  # Capture error and warning counts.
  @errors = nil
  @warnings = nil
  
  @stream.scan /(\d+) error\(s\), (\d+) warning\(s\)/ do |e, w|
    @errors   = e.to_i if e
    @warnings = w.to_i if w
  end
end

Instance Attribute Details

#compiler_include_pathsObject (readonly)

See Compilable interface.



16
17
18
# File 'lib/netlinx/compiler_result.rb', line 16

def compiler_include_paths
  @compiler_include_paths
end

#compiler_library_pathsObject (readonly)

See Compilable interface.



20
21
22
# File 'lib/netlinx/compiler_result.rb', line 20

def compiler_library_paths
  @compiler_library_paths
end

#compiler_module_pathsObject (readonly)

See Compilable interface.



18
19
20
# File 'lib/netlinx/compiler_result.rb', line 18

def compiler_module_paths
  @compiler_module_paths
end

#compiler_target_filesObject (readonly)

See Compilable interface.



14
15
16
# File 'lib/netlinx/compiler_result.rb', line 14

def compiler_target_files
  @compiler_target_files
end

#errorsObject (readonly)

Number of compiler errors.



7
8
9
# File 'lib/netlinx/compiler_result.rb', line 7

def errors
  @errors
end

#streamObject (readonly)

The raw stream of text returned by the compiler.



5
6
7
# File 'lib/netlinx/compiler_result.rb', line 5

def stream
  @stream
end

#warningsObject (readonly)

Number of compiler warnings.



9
10
11
# File 'lib/netlinx/compiler_result.rb', line 9

def warnings
  @warnings
end

Instance Method Details

#error_itemsArray<String>

Returns a list of errors.

Returns:

  • (Array<String>)

    a list of errors.



66
67
68
# File 'lib/netlinx/compiler_result.rb', line 66

def error_items
  @stream.scan(/(^ERROR: .*$)/).map {|i| i.first}
end

#success?Boolean

Returns true if compile was successful.

Returns:

  • (Boolean)

    true if compile was successful.



56
57
58
# File 'lib/netlinx/compiler_result.rb', line 56

def success?
  @errors == 0 && @warnings == 0
end

#target_fileString

Returns the absolute path of the source code file that was compiled.

Returns:

  • (String)

    the absolute path of the source code file that was compiled.



51
52
53
# File 'lib/netlinx/compiler_result.rb', line 51

def target_file
  @compiler_target_files.first
end

#to_sObject

Alias of #stream.



46
47
48
# File 'lib/netlinx/compiler_result.rb', line 46

def to_s
  @stream
end

#warning_itemsArray<String>

Returns a list of warnings.

Returns:

  • (Array<String>)

    a list of warnings.



61
62
63
# File 'lib/netlinx/compiler_result.rb', line 61

def warning_items
  @stream.scan(/(^WARNING: .*$)/).map {|i| i.first}
end