Class: Code
- Inherits:
-
Object
- Object
- Code
- Defined in:
- lib/vertigo/code.rb
Instance Attribute Summary collapse
-
#indent ⇒ Object
Returns the value of attribute indent.
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #<<(thing) ⇒ Object
- #clean(str) ⇒ Object
- #finalize ⇒ Object
-
#initialize(str = nil) ⇒ Code
constructor
A new instance of Code.
- #last ⇒ Object
- #newline ⇒ Object
- #save_as(filename, verbose = true) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(str = nil) ⇒ Code
Returns a new instance of Code.
5 6 7 8 9 |
# File 'lib/vertigo/code.rb', line 5 def initialize str=nil @lines=[] (@lines << str) if str @indent=0 end |
Instance Attribute Details
#indent ⇒ Object
Returns the value of attribute indent.
3 4 5 |
# File 'lib/vertigo/code.rb', line 3 def indent @indent end |
#lines ⇒ Object
Returns the value of attribute lines.
3 4 5 |
# File 'lib/vertigo/code.rb', line 3 def lines @lines end |
Instance Method Details
#<<(thing) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vertigo/code.rb', line 11 def <<(thing) if (code=thing).is_a? Code code.lines.each do |line| @lines << " "*@indent+line.to_s end elsif thing.is_a? Array thing.each do |kode| @lines << kode end elsif thing.nil? else @lines << " "*@indent+thing.to_s end end |
#clean(str) ⇒ Object
33 34 35 36 37 |
# File 'lib/vertigo/code.rb', line 33 def clean str str=str.gsub(/;[\s\n]*;/ ,';') str=str.gsub(/;[\s\n]*\)/ ,')') str=str.gsub(/,[\s\n]*\)/,')') end |
#finalize ⇒ Object
26 27 28 29 30 31 |
# File 'lib/vertigo/code.rb', line 26 def finalize str=@lines.join("\n") if @lines.any? str=clean(str) return str if @lines.any? "" end |
#last ⇒ Object
53 54 55 |
# File 'lib/vertigo/code.rb', line 53 def last @lines.last end |
#newline ⇒ Object
39 40 41 |
# File 'lib/vertigo/code.rb', line 39 def newline @lines << " " end |
#save_as(filename, verbose = true) ⇒ Object
43 44 45 46 47 |
# File 'lib/vertigo/code.rb', line 43 def save_as filename,verbose=true str=self.finalize File.open(filename,'w'){|f| f.puts(str)} return filename end |
#size ⇒ Object
49 50 51 |
# File 'lib/vertigo/code.rb', line 49 def size @lines.size end |