Class: MetricFu::Flog::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/metric_fu/flog.rb

Constant Summary collapse

METHOD_LINE_REGEX =
/([A-Za-z]+#.*):\s\((\d+\.\d+)\)/
OPERATOR_LINE_REGEX =
/\s+(\d+\.\d+):\s(.*)$/

Class Method Summary collapse

Class Method Details

.parse(text) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/metric_fu/flog.rb', line 53

def parse(text)
  score = text[/\w+ = (\d+\.\d+)/, 1]
  return nil unless score
  page = Page.new(score)

  text.each_line do |method_line|
   if match = method_line.match(METHOD_LINE_REGEX)
      page.scanned_methods << ScannedMethod.new(match[1], match[2])
    end
    
    if match = method_line.match(OPERATOR_LINE_REGEX)
      return if page.scanned_methods.empty?
      page.scanned_methods.last.operators << Operator.new(match[1], match[2])
    end
  end
  page
end