Sha256: 59d42250d58f7b1a37b15ca50ba6e3f088252c70e7cd7d10fac2a4865fe18557

Contents?: true

Size: 768 Bytes

Versions: 10

Compression:

Stored size: 768 Bytes

Contents

module Ezid
  class Batch
    include Enumerable

    attr_reader :format, :batch_file

    def initialize(format, batch_file)
      @format = format
      @batch_file = batch_file
    end

    def each(&block)
      case format
      when :anvl
        each_anvl(&block)
      when :xml
        each_xml(&block)
      when :csv
        each_csv(&block)
      end
    end

    def each_anvl(&block)
      File.open(batch_file, "rb") do |f|
        while record = f.gets("")
          head, metadata = record.split(/\n/, 2)
          id = head.sub(/\A::/, "").strip
          yield Identifier.load(id, metadata)
        end
      end
    end

    def each_xml
      raise NotImplementedError
    end

    def each_csv
      raise NotImplementedError
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ezid-client-1.10.0 lib/ezid/batch.rb
ezid-client-1.9.4 lib/ezid/batch.rb
ezid-client-1.9.3 lib/ezid/batch.rb
ezid-client-1.9.2 lib/ezid/batch.rb
ezid-client-1.9.1 lib/ezid/batch.rb
ezid-client-1.9.0 lib/ezid/batch.rb
ezid-client-1.9.0.rc1 lib/ezid/batch.rb
ezid-client-1.8.0 lib/ezid/batch.rb
ezid-client-1.7.1 lib/ezid/batch.rb
ezid-client-1.7.0 lib/ezid/batch.rb