Next / Previous / Contents / Shipman's homepage

8.5. class BirdId

Each instance of this class represents one simple or compound bird identity.

abbr.py
# - - - - -   c l a s s   B i r d I d   - - - - -

class BirdId:
    """Represents a single bird code, or two codes with a relationship.

      Exports:
        BirdId ( txny, abbr, rel=None, abbr2=None, q=None ):
          [ (txny is a Txny object) and
            (abbr is the first or only bird code) and
            (rel is REL_SIMPLE, REL_HYBRID, or REL_PAIR) and
            (abbr2 is None for rel=REL_SIMPLE, or the second
            bird code for rel != REL_SIMPLE) and
            (q is None normally or "?" for questionable ID) ->
              return a new BirdId representing that bird
              identification ]
        .txny:           [ as passed to constructor, read-only ]
        .abbr:           [ as passed to constructor, read-only ]
        .rel:            [ as passed to constructor, read-only ]
        .abbr2:          [ as passed to constructor, read-only ]
        .q:              [ as passed to constructor, read-only ]
        .fullAbbr:
          [ if self.rel == REL_SIMPLE -> self.abbr.rstrip()
            else ->
              self.abbr.rstrip() + self.rel + self.abbr2.rstrip() ]
        .taxon:
          [ a Taxon representing the smallest taxon in self.txny
            that contains abbr and, if present, abbr2 ]
        .normalize():
          [ self.abbr, uppercased and blank-padded to size ABBR_L ]
        .__str__():
          [ return self's English name ]
        BirdId.scan ( txny, scan ):    # Static method
          [ (txny is a Txny object) and (scan is a Scan object) ->
              if the current line of scan starts with a simple or
              compound bird code ->
                scan  :=  scan advanced past that code
                return a new BirdId object representing that code
              else ->
                scan  :=   scan advanced past valid-looking parts, if any
                scan  +:=  error message
                raise ValueError ]
        BirdId.scanFlat ( txny, scan ):     # Static method
          [ (txny is a Txny object) and (scan is a Scan object) ->
              if the current line of scan starts with a
              compound bird code in flat-field format ->
                scan  :=  scan advanced past that code
                return a new BirdId object representing that code
              else ->
                scan  :=   scan advanced past valid-looking parts, if any
                scan  +:=  error message
                raise ValueError ]
        BirdId.scanAbbr ( txny, scan ):     # Static method
          [ (txny is a Txny object) and (scan is a Scan object) ->
              if scan starts with a bird code valid in txny ->
                  scan  :=  scan advanced past that code
                  return that code
              else ->
                  scan  :=   scan advanced valid-looking parts, if any
                  scan  +:=  error message
                  raise ValueError ]
        BirdId.scanAbbrFlat ( txny, scan ): # Static method
          [ (txny is a Txny object) and (scan is a Scan object) ->
              if scan starts with a bird code valid in txny,
              right blank-padded to length ABBR_L ->
                scan  :=  scan advanced past that code
                return the code without its blank padding
              else ->
                scan  :=   scan advanced past valid-looking stuff if any
                scan  +:=  error message
                raise ValueError ]

      State/Invariants:
        self.abbr < self.abbr2
    """