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.
47 48 49 |
# File 'lib/sec_id/base.rb', line 47 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
42 43 44 |
# File 'lib/sec_id/base.rb', line 42 def check_digit(id) new(id).calculate_check_digit end |
.restore!(id_without_check_digit) ⇒ Object
38 39 40 |
# File 'lib/sec_id/base.rb', line 38 def restore!(id_without_check_digit) new(id_without_check_digit).restore! end |
.valid?(id) ⇒ Boolean
30 31 32 |
# File 'lib/sec_id/base.rb', line 30 def valid?(id) new(id).valid? end |
.valid_format?(id) ⇒ Boolean
34 35 36 |
# File 'lib/sec_id/base.rb', line 34 def valid_format?(id) new(id).valid_format? end |
Instance Method Details
#calculate_check_digit ⇒ Object
66 67 68 |
# File 'lib/sec_id/base.rb', line 66 def calculate_check_digit raise NotImplementedError end |
#restore! ⇒ Object
61 62 63 64 |
# File 'lib/sec_id/base.rb', line 61 def restore! @check_digit = calculate_check_digit @full_number = to_s end |
#to_s ⇒ Object Also known as: to_str
70 71 72 |
# File 'lib/sec_id/base.rb', line 70 def to_s "#{identifier}#{check_digit}" end |
#valid? ⇒ Boolean
51 52 53 54 55 |
# File 'lib/sec_id/base.rb', line 51 def valid? return false unless valid_format? check_digit == calculate_check_digit end |
#valid_format? ⇒ Boolean
57 58 59 |
# File 'lib/sec_id/base.rb', line 57 def valid_format? identifier ? true : false end |