Class: Ezid::Batch

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ezid/batch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format, batch_file) ⇒ Batch

Returns a new instance of Batch.



7
8
9
10
# File 'lib/ezid/batch.rb', line 7

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

Instance Attribute Details

#batch_fileObject (readonly)

Returns the value of attribute batch_file.



5
6
7
# File 'lib/ezid/batch.rb', line 5

def batch_file
  @batch_file
end

#formatObject (readonly)

Returns the value of attribute format.



5
6
7
# File 'lib/ezid/batch.rb', line 5

def format
  @format
end

Instance Method Details

#each(&block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/ezid/batch.rb', line 12

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

#each_anvl(&block) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/ezid/batch.rb', line 23

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

#each_csvObject

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/ezid/batch.rb', line 37

def each_csv
  raise NotImplementedError
end

#each_xmlObject

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/ezid/batch.rb', line 33

def each_xml
  raise NotImplementedError
end