Class: MetricFu::FlogReporter::Base

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

Constant Summary collapse

MODULE_NAME =
"([A-Z][a-z]+)+"
METHOD_NAME =
"#([a-z]+_?)+"
SCORE =
"\\d+\\.\\d+"
METHOD_NAME_RE =
Regexp.new("#{MODULE_NAME}#{METHOD_NAME}")
SCORE_RE =
Regexp.new(SCORE)
METHOD_LINE_RE =
Regexp.new("#{MODULE_NAME}#{METHOD_NAME}:\\s\\(#{SCORE}\\)")
OPERATOR_LINE_RE =
Regexp.new("\\s+(#{SCORE}):\\s(.*)$")

Class Method Summary collapse

Class Method Details

.cycle(first_value, second_value, iteration) ⇒ Object



21
22
23
24
# File 'lib/metric_fu/flog_reporter/base.rb', line 21

def cycle(first_value, second_value, iteration)
  return first_value if iteration % 2 == 0
  return second_value
end

.load_css(css_file = nil) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/metric_fu/flog_reporter/base.rb', line 26

def load_css(css_file = nil)
  filepath = css_file || File.join(File.dirname(__FILE__), 'flog_reporter.css')
  css = ""
  file = File.open(filepath, "r")
  file.each_line { |line| css << line }
  file.close
  css
end

.parse(text) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/metric_fu/flog_reporter/base.rb', line 35

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

  text.each_line do |method_line|
    if METHOD_LINE_RE =~ method_line and
       method_name = method_line[METHOD_NAME_RE] and
       score = method_line[SCORE_RE]
       page.scanned_methods << ScannedMethod.new(method_name, score)
    end

    if OPERATOR_LINE_RE =~ method_line and
       operator = method_line[OPERATOR_LINE_RE, 2] and
       score = method_line[SCORE_RE]
       raise InvalidFlog if page.scanned_methods.empty?
       page.scanned_methods.last.operators << Operator.new(score, operator)
    end
  end

  page
end