Sha256: da28160124a31bc2b22d0e403976bf6e5255a4a184af2d3d4a4aa6d41297a9d6

Contents?: true

Size: 893 Bytes

Versions: 4

Compression:

Stored size: 893 Bytes

Contents

require "virtus"
require "rubycritic/core/rating"

module Rubycritic

  class AnalysedFile
    include Virtus.model

    attribute :pathname
    attribute :smells
    attribute :churn
    attribute :committed_at
    attribute :complexity
    attribute :duplication
    attribute :methods_count

    def name
      @name ||= pathname.basename.sub_ext("").to_s
    end

    def path
      @path ||= pathname.to_s
    end

    def cost
      @cost ||= smells.map(&:cost).inject(0, :+) + (complexity / 25)
    end

    def rating
      @rating ||= Rating.from_cost(cost)
    end

    def complexity_per_method
      if methods_count == 0
        "N/A"
      else
        complexity.fdiv(methods_count).round(1)
      end
    end

    def has_smells?
      !smells.empty?
    end

    def smells_at_location(location)
      smells.select { |smell| smell.at_location?(location) }
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubycritic-1.0.2 lib/rubycritic/core/analysed_file.rb
rubycritic-1.0.1 lib/rubycritic/core/analysed_file.rb
rubycritic-1.0.0 lib/rubycritic/core/analysed_file.rb
rubycritic-0.0.16 lib/rubycritic/core/analysed_file.rb