Class: Zeno::FileGenerator
- Inherits:
-
Object
- Object
- Zeno::FileGenerator
- Defined in:
- lib/zeno/filegenerator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
- #add_var(name, value, assign = '=') ⇒ Object
- #del_var(name) ⇒ Object
- #generate ⇒ Object
-
#initialize(path) ⇒ FileGenerator
constructor
A new instance of FileGenerator.
- #to_s ⇒ Object
Constructor Details
#initialize(path) ⇒ FileGenerator
Returns a new instance of FileGenerator.
26 27 28 29 |
# File 'lib/zeno/filegenerator.rb', line 26 def initialize(path) @path = path @vars = Hash.new end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
21 22 23 |
# File 'lib/zeno/filegenerator.rb', line 21 def path @path end |
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
21 22 23 |
# File 'lib/zeno/filegenerator.rb', line 21 def vars @vars end |
Instance Method Details
#add_var(name, value, assign = '=') ⇒ Object
31 32 33 |
# File 'lib/zeno/filegenerator.rb', line 31 def add_var(name, value, assign = '=') @vars[name] = "#{assign} #{value}" end |
#del_var(name) ⇒ Object
35 36 37 |
# File 'lib/zeno/filegenerator.rb', line 35 def del_var(name) @vars.delete name end |
#generate ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/zeno/filegenerator.rb', line 39 def generate File.open(path, 'w') do |file| file.puts self.to_s end nil end |
#to_s ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/zeno/filegenerator.rb', line 47 def to_s output = "" @vars.each do |key, value| output += "#{key} #{value}\n" end output end |