app/helpers/type_materials/catalog_helper.rb
module TypeMaterials::CatalogHelper
# TODO: we should, perhaps, drive this off dwc_occurrence
# Return text only, no HTML.
# To be used in paper catalogs, this is to be human readable.
# If we need italics or bold use Markdown, and we will compile after that
def type_material_catalog_label(type_material, verbose = false) # Possibly parameterize biocurations: true, repository: true, identifiers: true
t = type_material
if t.nil? && verbose # Anticipate rendering in paper
return '[TODO: Add type material]'
elsif t.nil?
return nil
end
co = t.collection_object
ce = co.collecting_event
v = []
# Holotype male, adult, INHS 12312, deposited: <repoo name>. <verbatim_label>.
if co.ranged_lot_category.present?
v.push t.type_type.capitalize + "(n= #{ranged_lot_range(co.ranged_lot_category)})"
else
v.push t.type_type.capitalize + (co.total > 1 ? " (n= #{co.total})" : '')
end
v.push co.biocuration_classes.collect{|a| a.name.downcase}.join(', ').presence
# TODO: add verbose warning when missing any identifier
# TODO: add option(?) to render all identifiers
v.push label_for_identifier(
co.identifiers.prefer('Identifier::Local::CatalogNumber').first
)
if d = label_for_repository(co.repository)
v.push "deposited at: #{d}"
else
if verbose
v.push '[TODO: Repository NOT PROVIDED]'
end
end
if l = type_material_collecting_event_label(ce, verbose)
v.push l
else
v.push catalog_object_locality_label(co)
end
v.compact.join('; ')
end
# TODO: move to collection object catalog helper when that is developed
# leverage DwC index methods
def catalog_object_locality_label(collection_object)
o = collection_object.dwc_occurrence
[
o.country,
o.stateProvince,
o.county,
o.verbatimLocality,
].compact.join(': ')
end
# @return [String]
# Must return a string, if no value then the wqrning is returned
def type_material_collecting_event_label(collecting_event, verbose = false)
missing = '[TODO: A document (preferred) or verbatim label in a collecting event must be provided]'
if ce = collecting_event
if ce.document_label
return ::Utilities::Strings.linearize(ce.document_label)
elsif ce.verbatim_label
return ::Utilities::Strings.linearize(ce.verbatim_label)
end
end
verbose ? missing : nil
end
end