Class: CfScriptReader

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

Overview

Reads a file, integrates the specified arguments, and generates indented output taken specified parameters into account

Instance Method Summary collapse

Constructor Details

#initialize(file_to_read, indentation = 0) ⇒ CfScriptReader

Returns a new instance of CfScriptReader.



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

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

Instance Method Details

#apply_arguments(*arguments) ⇒ Object



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

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

#generateObject



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

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