Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions app/services/name/type_resolver.rb

This file was deleted.

25 changes: 25 additions & 0 deletions app/services/type_resolver_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

# Service object to resolve the nomenclatural type for a name.
# This encapsulates the logic for determining the type_of_type value
# and handling edge cases.
class TypeResolverService
# Resolves the nomenclatural type class for a given object.
# @param object [Object, nil] The object to resolve (e.g., a Name, Genome, or Strain).
# @return [String] The resolved type_of_type value, or 'unknown' if unresolved.
def self.resolve(object)
return 'unknown' if object.nil?
return object.type_of_type if object.respond_to?(:type_of_type)
'unknown'
end

# Resolves the nomenclatural type class for a given object, with additional context.
# @param object [Object, nil] The object to resolve.
# @param context [Hash] Additional context (e.g., { fallback: 'Name' }).
# @return [String] The resolved type_of_type value.
def self.resolve_with_context(object, context = {})
resolved = resolve(object)
return resolved unless resolved == 'unknown' && context[:fallback].present?
context[:fallback]
end
end
Loading