Class: Sal::Code
- Inherits:
-
Object
- Object
- Sal::Code
- Defined in:
- lib/sal/code.rb
Overview
The class code represent the complete code from a sal file. You can analyze the code now through the items, the libraries, … Only code in text format could be analyzed
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#format ⇒ Object
Returns the value of attribute format.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#add_library(filename) ⇒ Object
Add a new library to the libraries section in the code.
-
#classes ⇒ Object
Getter for the classes (lazy loading).
-
#display(smart = true) ⇒ Object
Returns a short overview over the code (version, format, …).
-
#externals ⇒ Object
Getter for the externals (lazy loading).
-
#generated_code ⇒ Object
Returns the current code from the items.
-
#initialize(filename) ⇒ Code
constructor
Initialize Code with filename The sourcecode will read and the format and version are analysed.
-
#items ⇒ Object
Getter for the items (lazy loading).
-
#libraries ⇒ Object
Getter for the libraries (lazy loading).
-
#save(new_filename = filename) ⇒ Object
Save the items of code back to disk Without parameters, the original file will be overridden.
-
#save_as(new_filename) ⇒ Object
Save the items of code back to disk in a new file Alias for save with a new filename.
- #to_s ⇒ Object
Constructor Details
#initialize(filename) ⇒ Code
Initialize Code with filename The sourcecode will read and the format and version are analysed
19 20 21 22 |
# File 'lib/sal/code.rb', line 19 def initialize( filename ) read_code_from_file filename get_format_and_version_from_code end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
36 37 38 |
# File 'lib/sal/code.rb', line 36 def code @code end |
#filename ⇒ Object
Returns the value of attribute filename.
36 37 38 |
# File 'lib/sal/code.rb', line 36 def filename @filename end |
#format ⇒ Object
Returns the value of attribute format.
36 37 38 |
# File 'lib/sal/code.rb', line 36 def format @format end |
#version ⇒ Object
Returns the value of attribute version.
36 37 38 |
# File 'lib/sal/code.rb', line 36 def version @version end |
Instance Method Details
#add_library(filename) ⇒ Object
Add a new library to the libraries section in the code
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sal/code.rb', line 58 def add_library(filename) # .head 1 + Libraries # .head 2 - File Include: qckttip.apl # .head 2 - File Include: vt.apl items.each do | item | if( item.level == 1 and item.code =~ /Libraries/ ) include_item = item.copy include_item.parent = item include_item.childs = [] include_item.code = "File Include: #{filename}" include_item.level = item.level + 1 @items.insert(@items.index(item) + 1, include_item) item.childs.insert(0, include_item) item.refresh_child_indicator include_item.refresh_child_indicator @libraries = nil return include_item end end end |
#classes ⇒ Object
Getter for the classes (lazy loading)
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/sal/code.rb', line 93 def classes if @classes.nil? @classes = [] items.each do | item | if( item.level == 3 and !item.parent.nil? and item.parent.code.start_with?("Class Definitions") ) @classes << Class.new(item) unless item.commented? end end end return @classes end |
#display(smart = true) ⇒ Object
Returns a short overview over the code (version, format, …)
119 120 121 122 123 124 125 |
# File 'lib/sal/code.rb', line 119 def display(smart = true) disp = "#{File.basename @filename} " disp += (smart ? "- " : ":\n") disp += "Version = #{@version.td} " disp += (smart ? "- " : "\n") disp += "Format = #{@format}" end |
#externals ⇒ Object
Getter for the externals (lazy loading)
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/sal/code.rb', line 80 def externals if @externals.nil? @externals = Array.new items.each do | item | if( item.level == 3 and !item.parent.nil? and item.parent.code =~ /External Functions/ ) @externals << External.new(item) unless item.commented? end end end return @externals end |
#generated_code ⇒ Object
Returns the current code from the items
110 111 112 113 114 115 116 |
# File 'lib/sal/code.rb', line 110 def generated_code new_code = "" items.each do | item | new_code += item.line end new_code end |
#items ⇒ Object
Getter for the items (lazy loading)
39 40 41 42 |
# File 'lib/sal/code.rb', line 39 def items get_items_from_code if @items.nil? @items end |
#libraries ⇒ Object
Getter for the libraries (lazy loading)
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sal/code.rb', line 45 def libraries if @libraries.nil? @libraries = Array.new items.each do | item | if( item.level == 2 and !item.parent.nil? and item.parent.code =~ /Libraries/) @libraries << Library.new(item) unless item.commented? end end end return @libraries end |
#save(new_filename = filename) ⇒ Object
Save the items of code back to disk Without parameters, the original file will be overridden
26 27 28 |
# File 'lib/sal/code.rb', line 26 def save( new_filename = filename ) save_code_to_file new_filename end |
#save_as(new_filename) ⇒ Object
Save the items of code back to disk in a new file Alias for save with a new filename
32 33 34 |
# File 'lib/sal/code.rb', line 32 def save_as( new_filename ) save_code_to_file new_filename end |
#to_s ⇒ Object
105 106 107 |
# File 'lib/sal/code.rb', line 105 def to_s @file_name end |