Sha256: 88d6277ab24ed1fe7c1398d832cef5235ef1f46596d217ff50389e2ee77223bf

Contents?: true

Size: 536 Bytes

Versions: 5

Compression:

Stored size: 536 Bytes

Contents

require "forwardable"
require "russianpost/barcode_validator"

module RussianPost
  class Barcode
    extend Forwardable

    def_delegator :barcode, :=~

    attr_reader :barcode

    def initialize(barcode)
      @barcode = barcode.strip.upcase
      raise InvalidBarcode unless valid?
    end

    def to_s
      barcode
    end

    def digits
      barcode[/\d+/].split("").map { |d| d.to_i }
    end

    private

    def valid?
      BarcodeValidator.validate(self)
    end
  end

  class InvalidBarcode < ArgumentError; end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
russianpost-0.4.5 lib/russianpost/barcode.rb
russianpost-0.4.4 lib/russianpost/barcode.rb
russianpost-0.4.3 lib/russianpost/barcode.rb
russianpost-0.4.2 lib/russianpost/barcode.rb
russianpost-0.4.1 lib/russianpost/barcode.rb