MetricFu::Flog

Attributes

pages[R]

Public Class Methods

verify_dependencies!() click to toggle source
# File lib/generators/flog.rb, line 8
def self.verify_dependencies!
  `flog --help`
  raise 'sudo gem install flog # if you want the flog tasks' unless $?.success?
end

Public Instance Methods

analyze() click to toggle source
# File lib/generators/flog.rb, line 59
def analyze
  @pages = []
  flog_results.each do |path|
    page = parse(open(path, "r") { |f| f.read })
    if page
      page.path = path.sub(metric_directory, "").sub(".txt", ".rb") 
      #don't include old cached flog results for files that no longer exist.
      if is_file_current?(page.path.to_s)
        @pages << page
      end
    end
  end
end
emit() click to toggle source
# File lib/generators/flog.rb, line 17
def emit
  metric_dir = MetricFu::Flog.metric_directory
  MetricFu.flog[:dirs_to_flog].each do |directory|
    directory = "." if directory=='./'
    files = Dir.glob("#{directory}/**/*.rb")
    files = remove_excluded_files(files)
    files.each do |filename|
      output_dir = "#{metric_dir}/#{filename.split("/")[0..-2].join("/")}"
      mkdir_p(output_dir, :verbose => false) unless File.directory?(output_dir)
      pathname         = Pathname.new(filename)
      if MetricFu::MD5Tracker.file_changed?(filename, metric_dir) 
            base_name = pathname.basename.to_s.gsub(/\..*$/,'.txt')
            editted_filename = File.join(pathname.dirname.to_s, base_name)
     `flog -ad #{filename} > #{metric_dir}/#{editted_filename}`
      end
    end
  end
rescue LoadError
  if RUBY_PLATFORM =~ /java/
    puts 'running in jruby - flog tasks not available'
  else
    puts 'sudo gem install flog # if you want the flog tasks'
  end
end
parse(text) click to toggle source
# File lib/generators/flog.rb, line 42
def parse(text)
  summary, methods_summary = text.split "\n\n"
  return unless summary
  score, average = summary.split("\n").map {|line| line[OPERATOR_LINE_REGEX, 1]}
  return nil unless score && methods_summary
  page = Flog::Page.new(score, average)
  methods_summary.each_line do |method_line|
    if match = method_line.match(METHOD_LINE_REGEX)
     page.scanned_methods << ScannedMethod.new(match[2], match[1])
    elsif 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
to_h() click to toggle source
# File lib/generators/flog.rb, line 73
def to_h
  number_of_methods = @pages.inject(0) {|count, page| count += page.scanned_methods.size}
  total_flog_score = @pages.inject(0) {|total, page| total += page.score}
  sorted_pages = @pages.sort_by {|page| page.highest_score }.reverse 
  {:flog => { :total => total_flog_score,
              :average => average_score(total_flog_score, number_of_methods),
              :pages => sorted_pages.map {|page| page.to_h}}}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.