""" invenio_tools.recordinst """ from .base import is_institute from .exception import RecordException from .record import Record MSG_INVALID_ARG = "Invalid argument record" MSG_INVALID_HOST = "Invalid record host" MSG_INVALID_RECORD = "Invalid record, it is not describing an institute" class RecordInst(Record): """The MARC record describing an institute. The relation between methods and MARC fields are the following:: ------------------------+-------------+ | | INSPIREHEP | ------------------------+-------------+ | institute identifier | 110 u | | future institute id | 110 t | | name | 110 b | | type of record | 980 a | ------------------------+-------------+ Args: record (Record): """ def __init__(self, record): if not isinstance(record, Record): raise RecordException(MSG_INVALID_ARG) if not is_institute(record): raise RecordException(MSG_INVALID_RECORD) if record.host() != "inspirehep.net": raise RecordException(MSG_INVALID_HOST) Record.__init__(self, record) def future_identifier(self): """Future identifier of the institute. Returns: str: the future inspirehep identifier or an empty string if the identifier is not defined. """ return self._get("110", "t") def identifier(self): """Identifier of the institute. Returns: str: the current inspirehep identifier (2015) or an empty string if it is not defined. """ return self._get("110", "u") def name(self): """ Name of the institute. Returns: str: the name of the institute or an empty string if it is not defined. """ return self._get("110", "a") def rex(self): """ Regular expression to search authors affiliate to the institute. Returns: str: the regular expression to search author affiliate to the institute in the store ``cds.cern.ch`` or ``inspirehep.net``. """ li = [self.identifier(), self.future_identifier(), self.name()] # protection against empty string # happen when one the identifier / full name is not defined # trigger by inspirehep.net/record/903100 where name is not defined. if "" in li: li.sort() li.reverse() idx = li.index("") return r"|".join(li[:idx]) else: return r"|".join(li)