Class: MetricFu::Saikuro::SFile
- Inherits:
-
Object
- Object
- MetricFu::Saikuro::SFile
- Defined in:
- lib/generators/saikuro.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
Class Method Summary collapse
Instance Method Summary collapse
- #filename ⇒ Object
- #filepath ⇒ Object
- #get_class_names ⇒ Object
- #get_elements ⇒ Object
-
#initialize(path) ⇒ SFile
constructor
A new instance of SFile.
- #merge_classes ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(path) ⇒ SFile
Returns a new instance of SFile.
126 127 128 129 130 131 132 133 |
# File 'lib/generators/saikuro.rb', line 126 def initialize(path) @path = path @file_handle = File.open(@path, "r") @elements = [] get_elements ensure @file_handle.close if @file_handle end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
124 125 126 |
# File 'lib/generators/saikuro.rb', line 124 def elements @elements end |
Class Method Details
.is_valid_text_file?(path) ⇒ Boolean
135 136 137 138 139 140 141 142 143 |
# File 'lib/generators/saikuro.rb', line 135 def self.is_valid_text_file?(path) File.open(path, "r") do |f| if f.eof? || !f.readline.match(/--/) return false else return true end end end |
Instance Method Details
#filename ⇒ Object
145 146 147 |
# File 'lib/generators/saikuro.rb', line 145 def filename File.basename(@path, '_cyclo.html') end |
#filepath ⇒ Object
149 150 151 |
# File 'lib/generators/saikuro.rb', line 149 def filepath File.dirname(@path) end |
#get_class_names ⇒ Object
209 210 211 212 213 214 215 216 217 |
# File 'lib/generators/saikuro.rb', line 209 def get_class_names class_names = [] @elements.each do |element| unless class_names.include?(element.name) class_names << element.name end end class_names end |
#get_elements ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/generators/saikuro.rb', line 158 def get_elements begin while (line = @file_handle.readline) do return [] if line.nil? || line !~ /\S/ element ||= nil if line.match /START/ unless element.nil? @elements << element element = nil end line = @file_handle.readline element = Saikuro::ParsingElement.new(line) elsif line.match /END/ @elements << element if element element = nil else element << line if element end end rescue EOFError nil end end |
#merge_classes ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/generators/saikuro.rb', line 183 def merge_classes new_elements = [] get_class_names.each do |target_class| elements = @elements.find_all {|el| el.name == target_class } complexity = 0 lines = 0 defns = [] elements.each do |el| complexity += el.complexity.to_i lines += el.lines.to_i defns << el.defs end new_element = {:class_name => target_class, :complexity => complexity, :lines => lines, :methods => defns.flatten.map {|d| d.to_h}} new_element[:methods] = new_element[:methods]. sort_by {|x| x[:complexity] }. reverse new_elements << new_element end @elements = new_elements if new_elements end |
#to_h ⇒ Object
153 154 155 156 |
# File 'lib/generators/saikuro.rb', line 153 def to_h merge_classes {:classes => @elements} end |