Sha256: 47f4f8f9c4b5d2546dc663ea48624e0b9ade274014780431a88cf6783b0b20b9

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require "rubycritic/analysers/flay"
require "rubycritic/core/smell"

module Rubycritic
  module SmellAdapter

    class Flay
      def initialize(paths)
        @flay = ::Rubycritic::Analyser::Flay.new(paths)
      end

      def smells
        @flay.hashes.map do |structural_hash, nodes|
          create_smell(structural_hash, nodes)
        end
      end

      private

      def create_smell(structural_hash, nodes)
        Smell.new(
          :locations => smell_locations(nodes),
          :context   => "#{similarity(structural_hash)} code",
          :message   => "found in #{nodes.size} nodes",
          :score     => @flay.masses[structural_hash],
          :type      => "DuplicateCode"
        )
      end

      def smell_locations(nodes)
        nodes.map do |node|
          Location.new(node.file, node.line)
        end.sort
      end

      def similarity(structural_hash)
        if @flay.identical[structural_hash]
          "Identical"
        else
          "Similar"
        end
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubycritic-0.0.14 lib/rubycritic/adapters/smell/flay.rb
rubycritic-0.0.13 lib/rubycritic/adapters/smell/flay.rb