Class: SecId::Base
- Inherits:
-
Object
- Object
- SecId::Base
- Defined in:
- lib/sec_id/base.rb
Instance Attribute Summary collapse
-
#check_digit ⇒ Object
readonly
Returns the value of attribute check_digit.
-
#full_number ⇒ Object
readonly
Returns the value of attribute full_number.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Class Method Summary collapse
- .check_digit(id) ⇒ Object
- .restore!(id_without_check_digit) ⇒ Object
- .valid?(id) ⇒ Boolean
- .valid_format?(id) ⇒ Boolean
Instance Method Summary collapse
- #calculate_check_digit ⇒ Object
-
#initialize(_sec_id_number) ⇒ Base
constructor
A new instance of Base.
- #restore! ⇒ Object
- #to_s ⇒ Object (also: #to_str)
- #valid? ⇒ Boolean
- #valid_format? ⇒ Boolean
Constructor Details
#initialize(_sec_id_number) ⇒ Base
Returns a new instance of Base.
45 46 47 |
# File 'lib/sec_id/base.rb', line 45 def initialize(_sec_id_number) raise NotImplementedError end |
Instance Attribute Details
#check_digit ⇒ Object (readonly)
Returns the value of attribute check_digit.
27 28 29 |
# File 'lib/sec_id/base.rb', line 27 def check_digit @check_digit end |
#full_number ⇒ Object (readonly)
Returns the value of attribute full_number.
27 28 29 |
# File 'lib/sec_id/base.rb', line 27 def full_number @full_number end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
27 28 29 |
# File 'lib/sec_id/base.rb', line 27 def identifier @identifier end |
Class Method Details
.check_digit(id) ⇒ Object
41 42 43 |
# File 'lib/sec_id/base.rb', line 41 def self.check_digit(id) new(id).calculate_check_digit end |
.restore!(id_without_check_digit) ⇒ Object
37 38 39 |
# File 'lib/sec_id/base.rb', line 37 def self.restore!(id_without_check_digit) new(id_without_check_digit).restore! end |
.valid?(id) ⇒ Boolean
29 30 31 |
# File 'lib/sec_id/base.rb', line 29 def self.valid?(id) new(id).valid? end |
.valid_format?(id) ⇒ Boolean
33 34 35 |
# File 'lib/sec_id/base.rb', line 33 def self.valid_format?(id) new(id).valid_format? end |
Instance Method Details
#calculate_check_digit ⇒ Object
64 65 66 |
# File 'lib/sec_id/base.rb', line 64 def calculate_check_digit raise NotImplementedError end |
#restore! ⇒ Object
59 60 61 62 |
# File 'lib/sec_id/base.rb', line 59 def restore! @check_digit = calculate_check_digit @full_number = to_s end |
#to_s ⇒ Object Also known as: to_str
68 69 70 |
# File 'lib/sec_id/base.rb', line 68 def to_s "#{identifier}#{check_digit}" end |
#valid? ⇒ Boolean
49 50 51 52 53 |
# File 'lib/sec_id/base.rb', line 49 def valid? return false unless valid_format? check_digit == calculate_check_digit end |
#valid_format? ⇒ Boolean
55 56 57 |
# File 'lib/sec_id/base.rb', line 55 def valid_format? identifier ? true : false end |