Class: Sal::Item
Overview
The class item represent one source code line of an sal file. The item has references to its parent and childs to navigate between the items in the source code.
Constant Summary
Constants included from Format
Format::INDENTED, Format::NORMAL, Format::TEXT
Instance Attribute Summary collapse
-
#childs ⇒ Object
Returns the value of attribute childs.
-
#code_line_nr ⇒ Object
Returns the value of attribute code_line_nr.
-
#format ⇒ Object
Returns the value of attribute format.
-
#original ⇒ Object
Returns the value of attribute original.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#parts ⇒ Object
Returns the value of attribute parts.
-
#tag ⇒ Object
Returns the value of attribute tag.
Instance Method Summary collapse
-
#analyzed? ⇒ Boolean
Is the item is ready analyzed?.
-
#behind_code ⇒ Object
Read the last carriage return line feed and (if exist) the binary data component.
-
#behind_code=(value) ⇒ Object
Set the last carriage return line feed and (if exist) the binary data component.
-
#child_indicator ⇒ Object
Returns a + if the item has childs, otherwise a - is returned.
-
#code ⇒ Object
Return the code of the line without outline and .data parts.
-
#code=(value) ⇒ Object
Set the code of the line.
-
#commented? ⇒ Boolean
Is the item or a parent of the item is a comment (so the item is commented too)?.
-
#copy ⇒ Object
Returns a new object (copied object) of the current source code from the item.
-
#initialize(line, file_format = nil) ⇒ Item
constructor
Create item.
-
#is_code_line? ⇒ Boolean
Is the line is a source code line (for example: Set sTest = “Hallo”) Look at command.rb too!.
-
#item_comment ⇒ Object
Change the item to a comment item if the item is not a comment item yet.
-
#item_commented? ⇒ Boolean
Is the item is a comment?.
-
#level ⇒ Object
Get the outline level.
-
#level=(value) ⇒ Object
Set the outline level.
-
#line ⇒ Object
Getter of the line.
-
#line=(value) ⇒ Object
Change the code line.
-
#refresh_child_indicator ⇒ Object
Refreshes the child indicator for the current code in the item.
-
#to_s ⇒ Object
Returns the line of code and not the object.
Methods included from Format
get_from_code, get_from_file, get_from_line
Constructor Details
#initialize(line, file_format = nil) ⇒ Item
Create item. The format parameter is optional. If the format parameter is not given, the format will be analyzed with the source code line.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sal/item.rb', line 15 def initialize( line, file_format = nil ) @original = line @format = file_format.nil? ? Format.get_from_line(line) : file_format self.line = line @commented = false @parent = nil # Item @childs = Array.new # Items @child_indicator = "-" @analyzed = false @code_line_nr = -1 @parts = [] analyze end |
Instance Attribute Details
#childs ⇒ Object
Returns the value of attribute childs.
121 122 123 |
# File 'lib/sal/item.rb', line 121 def childs @childs end |
#code_line_nr ⇒ Object
Returns the value of attribute code_line_nr.
122 123 124 |
# File 'lib/sal/item.rb', line 122 def code_line_nr @code_line_nr end |
#format ⇒ Object
Returns the value of attribute format.
121 122 123 |
# File 'lib/sal/item.rb', line 121 def format @format end |
#original ⇒ Object
Returns the value of attribute original.
121 122 123 |
# File 'lib/sal/item.rb', line 121 def original @original end |
#parent ⇒ Object
Returns the value of attribute parent.
121 122 123 |
# File 'lib/sal/item.rb', line 121 def parent @parent end |
#parts ⇒ Object
Returns the value of attribute parts.
122 123 124 |
# File 'lib/sal/item.rb', line 122 def parts @parts end |
#tag ⇒ Object
Returns the value of attribute tag.
122 123 124 |
# File 'lib/sal/item.rb', line 122 def tag @tag end |
Instance Method Details
#analyzed? ⇒ Boolean
Is the item is ready analyzed?
52 53 54 |
# File 'lib/sal/item.rb', line 52 def analyzed? @analyzed end |
#behind_code ⇒ Object
Read the last carriage return line feed and (if exist) the binary data component
117 118 119 |
# File 'lib/sal/item.rb', line 117 def behind_code @parts[6] end |
#behind_code=(value) ⇒ Object
Set the last carriage return line feed and (if exist) the binary data component
112 113 114 |
# File 'lib/sal/item.rb', line 112 def behind_code=(value) @parts[6] = value end |
#child_indicator ⇒ Object
Returns a + if the item has childs, otherwise a - is returned
102 103 104 |
# File 'lib/sal/item.rb', line 102 def child_indicator @parts[3] end |
#code ⇒ Object
Return the code of the line without outline and .data parts
97 98 99 |
# File 'lib/sal/item.rb', line 97 def code @parts[5] end |
#code=(value) ⇒ Object
Set the code of the line
92 93 94 |
# File 'lib/sal/item.rb', line 92 def code=(value) @parts[5] = value end |
#commented? ⇒ Boolean
Is the item or a parent of the item is a comment (so the item is commented too)?
36 37 38 39 40 41 42 43 |
# File 'lib/sal/item.rb', line 36 def commented? return true if item_commented? if parent.nil? return item_commented? else return parent.commented? end end |
#copy ⇒ Object
Returns a new object (copied object) of the current source code from the item. No infos of parent and childs included.
131 132 133 |
# File 'lib/sal/item.rb', line 131 def copy Item.new(self.line) end |
#is_code_line? ⇒ Boolean
Is the line is a source code line (for example: Set sTest = “Hallo”) Look at command.rb too!
58 59 60 |
# File 'lib/sal/item.rb', line 58 def is_code_line? Command.is_code_line? code end |
#item_comment ⇒ Object
Change the item to a comment item if the item is not a comment item yet
46 47 48 49 |
# File 'lib/sal/item.rb', line 46 def item_comment self.code = "! #{self.code}" unless item_commented? _analyze_commented end |
#item_commented? ⇒ Boolean
Is the item is a comment?
31 32 33 |
# File 'lib/sal/item.rb', line 31 def item_commented? return @commented end |
#level ⇒ Object
Get the outline level
87 88 89 |
# File 'lib/sal/item.rb', line 87 def level @parts[1].to_i end |
#level=(value) ⇒ Object
Set the outline level
82 83 84 |
# File 'lib/sal/item.rb', line 82 def level=(value) @parts[1] = value end |
#line ⇒ Object
Getter of the line. The line will create dynamicly from the line parts.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sal/item.rb', line 70 def line case @format when TEXT @parts.join when INDENTED ("\t"*@parts[1])+@parts[5]+@parts[6] else raise "Sal::Item#line: Runs only for TEXT and INDENTED format!" end end |
#line=(value) ⇒ Object
Change the code line. This will trigger the analyze.
63 64 65 66 |
# File 'lib/sal/item.rb', line 63 def line=(value) @original = value analyze end |
#refresh_child_indicator ⇒ Object
Refreshes the child indicator for the current code in the item
107 108 109 |
# File 'lib/sal/item.rb', line 107 def refresh_child_indicator @parts[3] = (@childs != nil and @childs.length > 0 ? "+" : "-") end |
#to_s ⇒ Object
Returns the line of code and not the object
125 126 127 |
# File 'lib/sal/item.rb', line 125 def to_s line end |