Sha256: 37162c6759487c43fcd24b0f2b3a98c0ad1d63b38efab24d647e499fc7a24edb

Contents?: true

Size: 1.29 KB

Versions: 36

Compression:

Stored size: 1.29 KB

Contents

module Inch
  module Evaluation
    # Evaluation::File is used in the Suggest API/CLI to determine
    # the importance of files
    class File
      attr_accessor :filename, :objects

      def initialize(filename, objects)
        self.filename = filename
        self.objects = objects.select do |o|
          o.filename == filename
        end
      end

      # @note added to be compatible with code objects
      def fullname
        filename
      end

      #
      # grade, priority and score are not meant to be displayed in the CLI
      # they are just for internal evaluation purposes
      #

      def grade
        median(grades.sort_by(&:to_sym))
      end

      def priority
        median(priorities.sort)
      end

      def score
        objects.select(&:undocumented?).size
      end

      private

      def grades
        objects.map(&:grade)
      end

      def priorities
        objects.map(&:priority)
      end

      def median(sorted_list)
        index = (sorted_list.size / 2).round
        sorted_list[index]
      end

      class << self
        def for(filename, objects)
          @cache ||= {}
          if (file = @cache[filename])
            file
          else
            @cache[filename] = new(filename, objects)
          end
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
inch-0.9.0.rc1 lib/inch/evaluation/file.rb
inch-0.8.0 lib/inch/evaluation/file.rb
inch-0.8.0.rc2 lib/inch/evaluation/file.rb
inch-0.8.0.rc1 lib/inch/evaluation/file.rb
inch-0.7.1 lib/inch/evaluation/file.rb
inch-0.7.0 lib/inch/evaluation/file.rb
inch-0.6.4 lib/inch/evaluation/file.rb
inch-0.6.3 lib/inch/evaluation/file.rb
inch-0.6.2 lib/inch/evaluation/file.rb
inch-0.6.1 lib/inch/evaluation/file.rb
inch-0.6.0 lib/inch/evaluation/file.rb
inch-0.6.0.rc6 lib/inch/evaluation/file.rb
inch-0.6.0.rc5 lib/inch/evaluation/file.rb
inch-0.6.0.rc4 lib/inch/evaluation/file.rb
inch-0.6.0.rc3 lib/inch/evaluation/file.rb
inch-0.6.0.rc2 lib/inch/evaluation/file.rb
inch-0.6.0.rc1 lib/inch/evaluation/file.rb
inch-0.5.10 lib/inch/evaluation/file.rb
inch-0.5.9 lib/inch/evaluation/file.rb
inch-0.5.8 lib/inch/evaluation/file.rb