Sha256: 5d5475d3c2e4901eefb78c2ea856d58d940995e25f0d337ded585490a0587ea7

Contents?: true

Size: 1.19 KB

Versions: 37

Compression:

Stored size: 1.19 KB

Contents

module Inch
  module Evaluation
    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

37 entries across 37 versions & 1 rubygems

Version Path
inch-0.4.7 lib/inch/evaluation/file.rb
inch-0.5.0.rc3 lib/inch/evaluation/file.rb
inch-0.5.0.rc2 lib/inch/evaluation/file.rb
inch-0.5.0.rc1 lib/inch/evaluation/file.rb
inch-0.4.6 lib/inch/evaluation/file.rb
inch-0.4.5 lib/inch/evaluation/file.rb
inch-0.4.4 lib/inch/evaluation/file.rb
inch-0.4.4.rc4 lib/inch/evaluation/file.rb
inch-0.4.4.rc3 lib/inch/evaluation/file.rb
inch-0.4.4.rc2 lib/inch/evaluation/file.rb
inch-0.4.4.rc1 lib/inch/evaluation/file.rb
inch-0.4.3 lib/inch/evaluation/file.rb
inch-0.4.3.rc2 lib/inch/evaluation/file.rb
inch-0.4.3.rc1 lib/inch/evaluation/file.rb
inch-0.4.2 lib/inch/evaluation/file.rb
inch-0.4.1 lib/inch/evaluation/file.rb
inch-0.4.0 lib/inch/evaluation/file.rb
inch-0.4.0.rc3 lib/inch/evaluation/file.rb
inch-0.4.0.rc2 lib/inch/evaluation/file.rb
inch-0.4.0.rc1 lib/inch/evaluation/file.rb