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
- #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.
81 82 83 84 85 86 |
# File 'lib/generators/saikuro.rb', line 81 def initialize(path) @path = path @file_handle = File.open(@path, "r") @elements = [] get_elements end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
79 80 81 |
# File 'lib/generators/saikuro.rb', line 79 def elements @elements end |
Class Method Details
.is_valid_text_file?(path) ⇒ Boolean
88 89 90 91 92 93 94 95 96 |
# File 'lib/generators/saikuro.rb', line 88 def self.is_valid_text_file?(path) File.open(path, "r") do |f| unless f.readline.match /--/ return false else return true end end end |
Instance Method Details
#filename ⇒ Object
98 99 100 |
# File 'lib/generators/saikuro.rb', line 98 def filename File.basename(@path, '_cyclo.html') end |
#get_class_names ⇒ Object
152 153 154 155 156 157 158 159 160 |
# File 'lib/generators/saikuro.rb', line 152 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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/generators/saikuro.rb', line 107 def get_elements begin while ( line = @file_handle.readline) do if line.match /START/ line = @file_handle.readline element = Saikuro::ParsingElement.new(line) elsif line.match /END/ @elements << element element = nil else element << line end end rescue EOFError nil end end |
#merge_classes ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/generators/saikuro.rb', line 126 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
102 103 104 105 |
# File 'lib/generators/saikuro.rb', line 102 def to_h merge_classes {:classes => @elements} end |