Class: Bookland::Identifier
- Inherits:
-
Object
- Object
- Bookland::Identifier
- Defined in:
- lib/bookland/identifier.rb
Instance Attribute Summary collapse
-
#digits ⇒ Object
readonly
Returns the value of attribute digits.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #checksum_digit ⇒ Object
- #data_digits ⇒ Object
-
#initialize(raw) ⇒ Identifier
constructor
A new instance of Identifier.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(raw) ⇒ Identifier
Returns a new instance of Identifier.
13 14 15 |
# File 'lib/bookland/identifier.rb', line 13 def initialize(raw) @digits = raw.split('') end |
Instance Attribute Details
#digits ⇒ Object (readonly)
Returns the value of attribute digits.
11 12 13 |
# File 'lib/bookland/identifier.rb', line 11 def digits @digits end |
Class Method Details
.calculate_checksum_digit(data_digits) ⇒ Object
7 8 9 |
# File 'lib/bookland/identifier.rb', line 7 def self.calculate_checksum_digit(data_digits) raise NotImplementedError end |
.valid?(raw) ⇒ Boolean
3 4 5 |
# File 'lib/bookland/identifier.rb', line 3 def self.valid?(raw) new(raw).valid? end |
Instance Method Details
#==(other) ⇒ Object
33 34 35 |
# File 'lib/bookland/identifier.rb', line 33 def ==(other) to_s == other.to_s end |
#checksum_digit ⇒ Object
21 22 23 |
# File 'lib/bookland/identifier.rb', line 21 def checksum_digit digits[-1] end |
#data_digits ⇒ Object
17 18 19 |
# File 'lib/bookland/identifier.rb', line 17 def data_digits digits[0...-1] end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/bookland/identifier.rb', line 25 def to_s digits.join end |
#valid? ⇒ Boolean
29 30 31 |
# File 'lib/bookland/identifier.rb', line 29 def valid? checksum_digit == recalculate_checksum_digit end |