class Bookland::Identifier

Attributes

digits[R]

Public Class Methods

calculate_checksum_digit(data_digits) click to toggle source
# File lib/bookland/identifier.rb, line 7
def self.calculate_checksum_digit(data_digits)
  raise NotImplementedError
end
new(raw) click to toggle source
# File lib/bookland/identifier.rb, line 13
def initialize(raw)
  @digits = raw.split('')
end
valid?(raw) click to toggle source
# File lib/bookland/identifier.rb, line 3
def self.valid?(raw)
  new(raw.to_s).valid?
end

Public Instance Methods

==(other) click to toggle source
# File lib/bookland/identifier.rb, line 33
def ==(other)
  to_s == other.to_s
end
checksum_digit() click to toggle source
# File lib/bookland/identifier.rb, line 21
def checksum_digit
  digits[-1]
end
data_digits() click to toggle source
# File lib/bookland/identifier.rb, line 17
def data_digits
  digits[0...-1]
end
to_s() click to toggle source
# File lib/bookland/identifier.rb, line 25
def to_s
  digits.join
end
valid?() click to toggle source
# File lib/bookland/identifier.rb, line 29
def valid?
  checksum_digit == recalculate_checksum_digit
end

Private Instance Methods

recalculate_checksum_digit() click to toggle source
# File lib/bookland/identifier.rb, line 39
def recalculate_checksum_digit
  self.class.calculate_checksum_digit(data_digits)
end