Class: Expander

Inherits:
Object
  • Object
show all
Includes:
CopyExpander, ExpanderConfig
Defined in:
lib/expander.rb

Overview

Command-line driver for COBOL copy expander utility.

Instance Method Summary collapse

Methods included from ExpanderConfig

#config_file, #hash, #load_config, #method_missing

Methods included from CopyExpander

#blank?, #break_up_source_line, #comment?, #commentize, #copy_statement_count, #expand_copybook, #has_copy_statement?, #init, #process, #reconstruct_line, #replace_tokens

Constructor Details

#initialize(argv = ARGV) ⇒ Expander

Returns a new instance of Expander.



11
12
13
# File 'lib/expander.rb', line 11

def initialize(argv=ARGV)
  @argv = argv
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ExpanderConfig

Instance Method Details

#close_expanded_fileObject



62
63
64
# File 'lib/expander.rb', line 62

def close_expanded_file
  @expanded_file.close
end

#close_source_fileObject



54
55
56
# File 'lib/expander.rb', line 54

def close_source_file
  @source_file.close
end

#eof?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/expander.rb', line 42

def eof?
  @eof
end

#open_expanded_fileObject



58
59
60
# File 'lib/expander.rb', line 58

def open_expanded_file
  @expanded_file = File.open("#{output_dir('.')}/#{expanded_file('TEMP.CBL')}", 'w')
end

#open_source_fileObject



46
47
48
49
50
51
52
# File 'lib/expander.rb', line 46

def open_source_file
  if @argv == nil || @argv[0] == nil
    abort 'Usage: expander name-of-cobol-source-file' 
  end
  @source_file = File.open("#{source_dir}/#{@argv[0]}", 'r')
  @eof = false
end

#process_sourceObject



24
25
26
27
28
29
30
# File 'lib/expander.rb', line 24

def process_source
  init
  begin
    output_line = process read_line
    write_from output_line.to_s unless output_line == nil
  end while @eof == false
end

#read_lineObject



32
33
34
35
36
# File 'lib/expander.rb', line 32

def read_line
  line = ('%-80.80s' % @source_file.readline.chomp)
  @eof = @source_file.eof?
  line
end

#runObject



15
16
17
18
19
20
21
22
# File 'lib/expander.rb', line 15

def run
  load_config @argv
  open_source_file
  open_expanded_file
  process_source
  close_expanded_file
  close_source_file
end

#write_from(line) ⇒ Object



38
39
40
# File 'lib/expander.rb', line 38

def write_from line
  @expanded_file.write ('%-80.80s' % line.chomp) + "\n"
end