Class: Specify::Model::AutoNumberingScheme

Inherits:
Object
  • Object
show all
Defined in:
lib/specify/models/auto_numbering_scheme.rb

Overview

Sequel::Model for Specify auto numbering schemes.

Instance Method Summary collapse

Instance Method Details

#before_createObject



26
27
28
29
30
31
# File 'lib/specify/models/auto_numbering_scheme.rb', line 26

def before_create
  self.Version = 0
  self.TimestampCreated = Time.now
  # TODO: set created_by
  super
end

#before_updateObject



33
34
35
36
37
38
# File 'lib/specify/models/auto_numbering_scheme.rb', line 33

def before_update
  self.Version += 1
  self.TimestampModified = Time.now
  # TODO: set modified_by
  super
end

#catalog_number?Boolean

-> true or false Returns true if the AutoNumberingScheme is for catalog numbers

Returns:

  • (Boolean)


42
43
44
# File 'lib/specify/models/auto_numbering_scheme.rb', line 42

def catalog_number?
  scheme_model == CollectionObject && scheme_type == :catalog_number
end

#incrementObject

-> String Returns the next available number formatted according to the scheme.



48
49
50
51
# File 'lib/specify/models/auto_numbering_scheme.rb', line 48

def increment
  @number_format ||= number_format
  @number_format.create(@number_format.incrementer(max) + 1)
end

#maxObject

-> String Returns the currently highest number in the scheme.



55
56
57
58
# File 'lib/specify/models/auto_numbering_scheme.rb', line 55

def max
  raise 'not implemented' unless catalog_number?
  collections.map(&:highest_catalog_number).compact.max
end

#number_formatObject

-> Specify::NumberFormat Returns a NumberFormat instance for the AutoNumberingScheme.



62
63
64
65
66
67
68
# File 'lib/specify/models/auto_numbering_scheme.rb', line 62

def number_format
  # TODO: get proper number format from xml
  case self.FormatName
  when 'CatalogNumberNumeric'
    NumberFormat.new
  end
end

#scheme_modelObject

-> Class Returns the model class using the numbering scheme (e.g. Specify::Model::CollectionObject).



73
74
75
76
77
78
79
80
# File 'lib/specify/models/auto_numbering_scheme.rb', line 73

def scheme_model
  case self.TableNumber
  when 1
    CollectionObject
  when 7
    Accession
  end
end

#scheme_typeObject

-> Symbol Returns the kind of numbering scheme (e.g. :catalog_number).



84
85
86
87
88
89
90
91
92
93
# File 'lib/specify/models/auto_numbering_scheme.rb', line 84

def scheme_type
  case self.SchemeName
  when 'Catalog Numbering Scheme'
    :catalog_number
  when 'Accession Numbering Scheme'
    :accession_number
  else
    :custom
  end
end