Class: Specify::Model::AutoNumberingScheme
- Inherits:
-
Object
- Object
- Specify::Model::AutoNumberingScheme
- Includes:
- Createable, Updateable
- Defined in:
- lib/specify/models/auto_numbering_scheme.rb
Overview
AutoNumberingSchemes represent automatically incrementable numbers (serial numbers such as catalog numbers or accession numbers).
An AutoNumberingScheme is scoped to one or more #collections (instances of Specify::Model::Collection) in the case of catalog numbers, one or more #divisions (instances of Specify::Model::Division) in the case of accession numbers. Serial numbers (incrementers) will be incremented across that scope.
An AutoNumberingScheme has a #number_format (an instance of Specify::NumberFormat) that determines the format of the number (auto-numbers in Specify are strings).
Instance Method Summary collapse
-
#catalog_number? ⇒ Boolean
Returns
trueifselfapplies to catalog numbers. -
#increment ⇒ Object
Returns the next available serial number in the scope of the scheme, formatted according to the #number_format.
-
#max ⇒ Object
Returns the currently highest number within the scope of self.
-
#number_format ⇒ Object
Returns the Specify::NumberFormat instance for the
self. -
#scheme_model ⇒ Object
Returns the model class the numbering scheme applies to; Specify::Model::CollectionObject for catalog numbers, Specify::Model::Accession for accession numbers.
-
#scheme_type ⇒ Object
Returns a symbol for the type of numbering scheme (
:catalog_number,accession_number, or:custom).
Methods included from Updateable
Methods included from Createable
Instance Method Details
#catalog_number? ⇒ Boolean
Returns true if self applies to catalog numbers.
41 42 43 |
# File 'lib/specify/models/auto_numbering_scheme.rb', line 41 def catalog_number? scheme_model == CollectionObject && scheme_type == :catalog_number end |
#increment ⇒ Object
Returns the next available serial number in the scope of the scheme, formatted according to the #number_format.
47 48 49 50 |
# File 'lib/specify/models/auto_numbering_scheme.rb', line 47 def increment @number_format ||= number_format @number_format.create(@number_format.incrementer(max) + 1) end |
#max ⇒ Object
Returns the currently highest number within the scope of self. Currently only supports catalog numbers.
54 55 56 57 |
# File 'lib/specify/models/auto_numbering_scheme.rb', line 54 def max raise 'not implemented' unless catalog_number? collections.map(&:highest_catalog_number).compact.max end |
#number_format ⇒ Object
Returns the Specify::NumberFormat instance for the self.
60 61 62 63 64 65 66 |
# File 'lib/specify/models/auto_numbering_scheme.rb', line 60 def number_format # TODO: get proper number format from xml case self.FormatName when 'CatalogNumberNumeric' NumberFormat.new end end |
#scheme_model ⇒ Object
Returns the model class the numbering scheme applies to; Specify::Model::CollectionObject for catalog numbers, Specify::Model::Accession for accession numbers.
71 72 73 74 75 76 77 78 |
# File 'lib/specify/models/auto_numbering_scheme.rb', line 71 def scheme_model case self.TableNumber when 1 CollectionObject when 7 Accession end end |
#scheme_type ⇒ Object
Returns a symbol for the type of numbering scheme (:catalog_number, accession_number, or :custom).
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/specify/models/auto_numbering_scheme.rb', line 82 def scheme_type case self.SchemeName when 'Catalog Numbering Scheme' :catalog_number when 'Accession Numbering Scheme' :accession_number else :custom end end |