Class: Code
- Inherits:
-
Object
- Object
- Code
- Defined in:
- lib/reggae/code.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#indent ⇒ Object
Returns the value of attribute indent.
Instance Method Summary collapse
- #<<(str) ⇒ Object
- #clean_vhdl(str) ⇒ Object
- #empty? ⇒ Boolean
- #finalize(dot = false) ⇒ Object
-
#initialize(indent = 0) ⇒ Code
constructor
A new instance of Code.
- #newline ⇒ Object
- #save_as(filename, verbose = true) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(indent = 0) ⇒ Code
Returns a new instance of Code.
5 6 7 8 |
# File 'lib/reggae/code.rb', line 5 def initialize indent=0 @code=[] @indent=indent end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
3 4 5 |
# File 'lib/reggae/code.rb', line 3 def code @code end |
#indent ⇒ Object
Returns the value of attribute indent.
3 4 5 |
# File 'lib/reggae/code.rb', line 3 def indent @indent end |
Instance Method Details
#<<(str) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# 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) ⇒ Object
50 51 52 53 |
# File 'lib/reggae/code.rb', line 50 def clean_vhdl str str1=str.gsub(/\;\s*\)/,")") str2=str1.gsub(/\,\s*\)/,")") end |
#empty? ⇒ Boolean
10 11 12 |
# File 'lib/reggae/code.rb', line 10 def empty? @code.size==0 end |
#finalize(dot = false) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/reggae/code.rb', line 25 def finalize dot=false if dot return @code.join('\n') end @code.join("\n") end |
#newline ⇒ Object
32 33 34 |
# File 'lib/reggae/code.rb', line 32 def newline @code << " " end |
#save_as(filename, verbose = true) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# 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 ⇒ Object
46 47 48 |
# File 'lib/reggae/code.rb', line 46 def size @code.size end |