Class: GenericID
- Inherits:
-
Object
show all
- Defined in:
- lib/brid/ids/generic_id.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(number) ⇒ GenericID
Returns a new instance of GenericID.
6
7
8
9
10
|
# File 'lib/brid/ids/generic_id.rb', line 6
def initialize number
@number = clear_number(number)
@number = @number.rjust number_length, '0' if number_length > 0 and @number.length != number_length
end
|
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
5
6
7
|
# File 'lib/brid/ids/generic_id.rb', line 5
def number
@number
end
|
Instance Method Details
#check_digits ⇒ Object
12
13
14
15
16
|
# File 'lib/brid/ids/generic_id.rb', line 12
def check_digits
@check_digits ||= begin
@number[-check_digits_length, check_digits_length]
end
end
|
#check_digits_length ⇒ Object
3
|
# File 'lib/brid/ids/generic_id.rb', line 3
def check_digits_length; 1; end
|
#freeze ⇒ Object
34
35
36
37
38
|
# File 'lib/brid/ids/generic_id.rb', line 34
def freeze
check_digits
valid?
super
end
|
#invalid_sequential? ⇒ Boolean
40
41
42
43
44
|
# File 'lib/brid/ids/generic_id.rb', line 40
def invalid_sequential?
@invalid_sequential ||=begin
sequential.chars.to_a.uniq.count.eql? 1
end
end
|
#number_length ⇒ Object
2
|
# File 'lib/brid/ids/generic_id.rb', line 2
def number_length; 0; end
|
#sequential ⇒ Object
18
19
20
21
22
|
# File 'lib/brid/ids/generic_id.rb', line 18
def sequential
@sequential ||= begin
@number[0, @number.length - check_digits_length]
end
end
|
#to_s ⇒ Object
46
47
48
|
# File 'lib/brid/ids/generic_id.rb', line 46
def to_s
"#{sequential}-#{check_digits}"
end
|
#valid? ⇒ Boolean
24
25
26
27
28
29
30
31
32
|
# File 'lib/brid/ids/generic_id.rb', line 24
def valid?
return @valid if self.frozen?
@valid ||= begin
valid_number == @number and not invalid_sequential?
rescue TypeError
false
end
end
|