class RussianPost::Barcode::Base

Attributes

barcode[R]
digits[R]

Public Class Methods

format() click to toggle source
# File lib/russianpost/barcode/base.rb, line 12
def self.format
  /.*/
end
new(barcode) click to toggle source
# File lib/russianpost/barcode/base.rb, line 16
def initialize(barcode)
  @barcode = barcode.strip.upcase
  @digits  = barcode.scan(/\d/).map { |d| d.to_i }
end

Public Instance Methods

to_s() click to toggle source
# File lib/russianpost/barcode/base.rb, line 25
def to_s
  barcode
end
valid?() click to toggle source
# File lib/russianpost/barcode/base.rb, line 21
def valid?
  (barcode =~ self.class.format || false) && digits.last == checkdigit
end