class FrontendRouter
  attr_reader :id_type, :id
  def initialize(id_type, id)
    @id_type = id_type || ''
    @id = id
  end

  def url
    (entity, query_field) = query_info
    if [entity, query_field, id].any? { |i| i.blank? }
      nil
    else
      if entity.new.respond_to?('tag')
        id.sub!(entity.new.tag, '')
      end
      obj = entity.find_by!(query_field => id)
      adaptor = "LinkAdaptors::#{obj.class}".constantize.new(obj)
      "#{domain}#{adaptor.base_path}"
    end
  end

  private
  def query_info
    case id_type
    when /genes?/
      [ Gene, :id, ]
    when /variants?\z/
      [ Variant, :id, ]
    when /evidence/, /evidence_items?/
      [ EvidenceItem, :id, ]
    when /entrez/
      [ Gene, :entrez_id, ]
    when /variant_groups?/
      [ VariantGroup, :id, ]
    when /revisions?/
      [ SuggestedChange, :id ]
    when /assertions?/
      [ Assertion, :id ]
    when /allele_registry/
      [ Variant, :allele_registry_id, ]
    else
      []
    end
  end

  def domain
    'https://civic.genome.wustl.edu/'
  end
end

class FrontendRouter
  attr_reader :id_type, :id
  def initialize(id_type, id)
    @id_type = id_type || ''
    @id = id
  end

  def url
    (entity, query_field) = query_info
    if [entity, query_field, id].any? { |i| i.blank? }
      nil
    else
      if entity.new.respond_to?('tag')
        id.sub!(entity.new.tag, '')
      end
      obj = entity.find_by!(query_field => id)
      adaptor = "LinkAdaptors::#{obj.class}".constantize.new(obj)
      "#{domain}#{adaptor.base_path}"
    end
  end

  private
  def query_info
    case id_type
    when /genes?/
      [ Gene, :id, ]
    when /variants?\z/
      [ Variant, :id, ]
    when /evidence/, /evidence_items?/
      [ EvidenceItem, :id, ]
    when /entrez_id/
      [ Gene, :entrez_id, ]
    when /entrez_name/
      [ Gene, :name , ]
    when /variant_groups?/
      [ VariantGroup, :id, ]
    when /revisions?/
      [ SuggestedChange, :id ]
    when /assertions?/
      [ Assertion, :id ]
    when /allele_registry/
      [ Variant, :allele_registry_id, ]
    else
      []
    end
  end

  def domain
    'https://civic.genome.wustl.edu/'
  end
end

Support gene names in the direct linking
Support gene names in the direct linking
