Sha256: 1df9d8a4dfc02c34b267ce4f5a0d5d55a106a0d938eea5a11242179d4cf94ad6

Contents?: true

Size: 626 Bytes

Versions: 2

Compression:

Stored size: 626 Bytes

Contents

require "russianpost/client"
require "russianpost/operations_factory"

module RussianPost
  class Parcel
    attr_reader :barcode, :client

    def initialize(barcode, client: Client)
      @barcode = barcode.upcase
      @client  = client.new

      raise InvalidBarcode unless barcode_is_valid?
    end

    def operations
      @operations ||= fetch_operations
    end

    private

    def fetch_operations
      OperationsFactory.build(client.call(barcode: barcode))
    end

    def barcode_is_valid?
      barcode =~ /\A([A-Z]{2}\d{9}[A-Z]{2})|(\d{14})\z/
    end
  end

  class InvalidBarcode < ArgumentError; end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
russianpost-0.2.1 lib/russianpost/parcel.rb
russianpost-0.2.0 lib/russianpost/parcel.rb