Class: Specify::NumberFormat
- Inherits:
-
Object
- Object
- Specify::NumberFormat
- Defined in:
- lib/specify/number_format.rb
Overview
NumberFormats represent auto numbering formatters in a Specify::Database. Number formats in Specify are applied to Strings, to ensure they conform to a defined format.
If the NumberFormat can be auto-incremented, it will have a serial number part, the incrementer.
Instance Attribute Summary collapse
-
#incrementer_length ⇒ Object
The number of digits (length) of the serial number part.
Class Method Summary collapse
-
.from_xml(format_node) ⇒ Object
Not implemented.
-
.parse(format_string) ⇒ Object
Not implemented.
Instance Method Summary collapse
-
#create(number) ⇒ Object
Returns a new formatted String for
number. -
#incrementer(number_string) ⇒ Object
Returns the serial number part (incrementer) of the formatted
number_string. -
#initialize(incrementer_length = 9, options = {}) ⇒ NumberFormat
constructor
Returns a new NumberFormat.
-
#numeric? ⇒ Boolean
Returns
trueif theselfis a numeric NumberFormat. -
#template ⇒ Object
Returns a String template for
self, where # marks a digit of the incrementer (serial number part). -
#to_regexp ⇒ Object
Returns a Regexp to match the match the incrementer in the NumberFormat.
Constructor Details
#initialize(incrementer_length = 9, options = {}) ⇒ NumberFormat
Returns a new NumberFormat
options is not implemented; if empty, the NumberFormat will be numeric, i.e. consist only of the incrementer.
23 24 25 26 |
# File 'lib/specify/number_format.rb', line 23 def initialize(incrementer_length = 9, = {}) @incrementer_length = incrementer_length = end |
Instance Attribute Details
#incrementer_length ⇒ Object
The number of digits (length) of the serial number part.
12 13 14 |
# File 'lib/specify/number_format.rb', line 12 def incrementer_length @incrementer_length end |
Class Method Details
.from_xml(format_node) ⇒ Object
Not implemented
15 16 17 |
# File 'lib/specify/number_format.rb', line 15 def self.from_xml(format_node) # TODO: implement end |
.parse(format_string) ⇒ Object
Not implemented
29 30 31 |
# File 'lib/specify/number_format.rb', line 29 def self.parse(format_string) # TODO: implement end |
Instance Method Details
#create(number) ⇒ Object
Returns a new formatted String for number
34 35 36 |
# File 'lib/specify/number_format.rb', line 34 def create(number) number.to_s.rjust(incrementer_length, '0') if numeric? end |
#incrementer(number_string) ⇒ Object
Returns the serial number part (incrementer) of the formatted number_string.
40 41 42 |
# File 'lib/specify/number_format.rb', line 40 def incrementer(number_string) return number_string.to_i if numeric? end |
#numeric? ⇒ Boolean
Returns true if the self is a numeric NumberFormat.
45 46 47 |
# File 'lib/specify/number_format.rb', line 45 def numeric? .empty? end |
#template ⇒ Object
Returns a String template for self, where # marks a digit of the incrementer (serial number part).
51 52 53 |
# File 'lib/specify/number_format.rb', line 51 def template return '#' * incrementer_length if numeric? end |
#to_regexp ⇒ Object
Returns a Regexp to match the match the incrementer in the NumberFormat.
56 57 58 |
# File 'lib/specify/number_format.rb', line 56 def to_regexp return /^(?<incrementer>\d{#{incrementer_length}})$/ if numeric? end |