Sha256: 71e63d4c488656ef1233c8d3f92df24e17e028e8ba9f92a058c33c4a9d727d81

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

class ParsedFile

  include PoroPlus
  include Ephemeral::Base

  attr_accessor :complexity, :path_to_file, :class_name, :path_to_results
  attr_accessor :lines_of_code, :source

  def class_name
    @class_name ||= analyzer.extract_class_name
  end

  def content
    @content ||= File.open(path_to_file, "r").read
  end

  def analyzer
    @analyzer ||= Analyzer.new(content)
  end

  def average_complexity
    methods.map(&:complexity).reduce(:+) / methods.count.to_f
  end

  def complexity
    @complexity ||= analyzer.complexity
  end

  def methods
    @methods ||= analyzer.extract_methods
  end

  def source
    return @source if @source
    end_pos = 0
    self.lines_of_code = []
    @source = File.readlines(self.path_to_file).each_with_index do |line, index|
      start_pos = end_pos + 1
      end_pos += line.size
      self.lines_of_code << LineOfCode.new(line_number: index + 1, range: (start_pos..end_pos))
      line
    end.join
  end

  def summary
    {
      path_to_file: self.path_to_file,
      source: source,
      class_name: self.class_name,
      complexity: complexity
    }
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fukuzatsu-1.0.4 lib/fukuzatsu/parsed_file.rb
fukuzatsu-1.0.3 lib/fukuzatsu/parsed_file.rb
fukuzatsu-1.0.2 lib/fukuzatsu/parsed_file.rb
fukuzatsu-1.0.1 lib/fukuzatsu/parsed_file.rb
fukuzatsu-1.0.0 lib/fukuzatsu/parsed_file.rb