Class: Zeno::FileGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/zeno/filegenerator.rb

Direct Known Subclasses

Makefile

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (readonly)

Returns the value of attribute path.



21
22
23
# File 'lib/zeno/filegenerator.rb', line 21

def path
  @path
end

#varsObject (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

#generateObject



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_sObject



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