Class: CfFactory::CfScriptReader
- Inherits:
-
Object
- Object
- CfFactory::CfScriptReader
- Defined in:
- lib/cf_factory/base/cf_script_reader.rb
Instance Method Summary collapse
- #apply_arguments(*arguments) ⇒ Object
- #generate ⇒ Object
-
#initialize(file_to_read, indentation = 0) ⇒ CfScriptReader
constructor
A new instance of CfScriptReader.
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 |
#generate ⇒ Object
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 |