Sha256: b16efe62da52f9e9f530c713fb4f9c3620d4da3cb032c9f9de44b78959e28648

Contents?: true

Size: 1.91 KB

Versions: 28

Compression:

Stored size: 1.91 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)
            score_for_mention = per_param
            score_for_type = 0
            {
              Role::FunctionParameter::WithWrongMention =>
                -score_for(:parameters),
              Role::FunctionParameter::WithMention => score_for_mention,
              Role::FunctionParameter::WithoutMention => score_for_mention,
              Role::FunctionParameter::WithType => score_for_type,
              Role::FunctionParameter::WithoutType => score_for_type,
              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

28 entries across 28 versions & 1 rubygems

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