Class: CfFactory::CfScriptReader

Inherits:
Object
  • Object
show all
Defined in:
lib/cf_factory/base/cf_script_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_to_read, indentation = 0) ⇒ CfScriptReader

Returns a new instance of CfScriptReader.



4
5
6
7
# File 'lib/cf_factory/base/cf_script_reader.rb', line 4

def initialize(file_to_read, indentation = 0)
  @file = file_to_read
  @indent = indentation
end

Instance Method Details

#apply_arguments(*arguments) ⇒ Object



9
10
11
12
# File 'lib/cf_factory/base/cf_script_reader.rb', line 9

def apply_arguments(*arguments)
  @arguments = arguments
  puts @arguments.inspect     
end

#generateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cf_factory/base/cf_script_reader.rb', line 14

def generate()
  contents = File.open(@file, "r") {|f| f.read}
  count = 1
  @arguments.each() {|arg|
    pattern = /<\$#{count}>/
    puts "pattern = #{pattern.inspect}"
    contents.gsub!(pattern, arg)
    count += 1
  }
  result = ""
  contents.each_line do |line|
    result += "#{' '*@indent}#{line}"
  end
  result
end