class Code

Attributes

code[RW]
indent[RW]

Public Class Methods

new(indent=0) click to toggle source
# File lib/reggae/code.rb, line 5
def initialize indent=0
  @code=[]
  @indent=indent
end

Public Instance Methods

<<(str) click to toggle source
# File lib/reggae/code.rb, line 14
def <<(str)
  if str.is_a? Code
    str.code.each do |line|
      @code << " "*@indent+line
    end
  elsif str.nil?
  else
    @code << " "*@indent+str
  end
end
clean_vhdl(str) click to toggle source
# File lib/reggae/code.rb, line 50
def clean_vhdl str
  str1=str.gsub(/\;\s*\)/,")")
  str2=str1.gsub(/\,\s*\)/,")")
end
empty?() click to toggle source
# File lib/reggae/code.rb, line 10
def empty?
  @code.size==0
end
finalize(dot=false) click to toggle source
# File lib/reggae/code.rb, line 25
def finalize dot=false
  if dot
    return @code.join('\n')
  end
  @code.join("\n")
end
newline() click to toggle source
# File lib/reggae/code.rb, line 32
def newline
  @code << " "
end
save_as(filename,verbose=true) click to toggle source
# File lib/reggae/code.rb, line 36
def save_as filename,verbose=true
  str=self.finalize
  if filename.end_with? ".vhd"
    str=clean_vhdl(str)
  end
  File.open(filename,'w'){|f| f.puts(str)}
  puts "saved code in file #{filename}" if verbose
  return filename
end
size() click to toggle source
# File lib/reggae/code.rb, line 46
def size
  @code.size
end