Class: Specify::NumberFormat

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

Overview

A class to work with Specify number formats.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incrementer_length = 9, options = {}) ⇒ NumberFormat

Returns a new instance of NumberFormat



8
9
10
11
# File 'lib/specify/number_format.rb', line 8

def initialize(incrementer_length = 9, options = {})
  @incrementer_length = incrementer_length
  @options = options
end

Instance Attribute Details

#incrementer_lengthObject

Returns the value of attribute incrementer_length



6
7
8
# File 'lib/specify/number_format.rb', line 6

def incrementer_length
  @incrementer_length
end

Class Method Details

.from_xml(format_node) ⇒ Object



17
18
19
# File 'lib/specify/number_format.rb', line 17

def self.from_xml(format_node)
  # TODO: implement
end

.parse(format_string) ⇒ Object



13
14
15
# File 'lib/specify/number_format.rb', line 13

def self.parse(format_string)
  # TODO: implement
end

Instance Method Details

#create(number) ⇒ Object

-> String Returns a new formatted number string for number



23
24
25
# File 'lib/specify/number_format.rb', line 23

def create(number)
  number.to_s.rjust(incrementer_length, '0') if numeric?
end

#incrementer(number_string) ⇒ Object

-> Integer Returns the incrementing numeric part of the full catalog number String. number: the full Specify catalog number as String.



30
31
32
# File 'lib/specify/number_format.rb', line 30

def incrementer(number_string)
  return number_string.to_i if numeric?
end

#numeric?Boolean

-> true or false Returns true if the NumberFormat is numeric.

Returns:

  • (Boolean)


36
37
38
# File 'lib/specify/number_format.rb', line 36

def numeric?
  @options.empty?
end

#templateObject

-> String Returns a template string for the CatalogNumber, where # mark integer digits of the incrementer.



43
44
45
# File 'lib/specify/number_format.rb', line 43

def template
  return '#' * incrementer_length if numeric?
end

#to_regexpObject

-> Regexp Returns a regular expression to match the



49
50
51
# File 'lib/specify/number_format.rb', line 49

def to_regexp
  return /^(?<incrementer>\d{#{incrementer_length}})$/ if numeric?
end