Sha256: bb5165e5e4be9caa1dcc824b5095bb9139eb143bb7751aad6348b93dd6bac495

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

module Inch
  module Language
    module Elixir
      module Evaluation
        # Proxy class for functions
        class FunctionObject < Base
          def evaluate
            super
            evaluate_parameters
          end

          protected

          def relevant_roles
            relevant_base_roles.merge(relevant_function_roles)
          end

          private

          def evaluate_parameters
            params = object.parameters
            per_param = score_for_single_parameter
            params.each do |param|
              role_classes = relevant_parameter_roles(param, per_param)
              __evaluate(param, role_classes)
            end
          end

          def relevant_function_roles
            {
              Role::Function::Getter => nil,
              Role::Function::Setter => nil,
              Role::Function::Overridden =>
                if object.overridden?
                  object.overridden_method.score
                else
                  nil
                end,
              Role::Function::WithBangName => nil,
              Role::Function::WithQuestioningName => nil
            }
          end

          def relevant_parameter_roles(param, per_param)
            {
              Role::FunctionParameter::WithWrongMention =>
                -score_for(:parameters),
              Role::FunctionParameter::WithMention => per_param * 0.5,
              Role::FunctionParameter::WithoutMention => per_param * 0.5,
              Role::FunctionParameter::WithType => per_param * 0.5,
              Role::FunctionParameter::WithoutType => per_param * 0.5,
              Role::FunctionParameter::WithBadName => nil,
            }
          end

          def score_for_single_parameter
            @param_score ||= score_for(:parameters) / object.parameters.size
          end

        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
inch-0.5.0.rc11 lib/inch/language/elixir/evaluation/function_object.rb
inch-0.5.0.rc10 lib/inch/language/elixir/evaluation/function_object.rb
inch-0.5.0.rc9 lib/inch/language/elixir/evaluation/function_object.rb