Class: Bulkrax::ParserExportRecordSet::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
app/parsers/bulkrax/parser_export_record_set.rb

Overview

This class is abstract.
Note:

This has #each and #count but is not an Enumerable. But because it has these two methods that echo Array, we can do some lovely mocking and stubbing in those classes dependent on this file. :)

Direct Known Subclasses

All, Collection, Importer, Worktype

Instance Method Summary collapse

Constructor Details

#initialize(parser:) ⇒ Base

Returns a new instance of Base.



54
55
56
# File 'app/parsers/bulkrax/parser_export_record_set.rb', line 54

def initialize(parser:)
  @parser = parser
end

Instance Method Details

#countInteger

Returns:

  • (Integer)


65
66
67
68
69
70
# File 'app/parsers/bulkrax/parser_export_record_set.rb', line 65

def count
  sum = works.count + collections.count + file_sets.count
  return sum if limit.zero?
  return limit if sum > limit
  return sum
end

#each {|id, entry_class| ... } ⇒ Object

Note:

The order of what we yield has been previously determined.

Yield first the works, then collections, then file sets. Once we’ve yielded as many times as the parser’s limit, we break the iteration and return.

Yield Parameters:

  • id (String)

    The ID of the work/collection/file_set

  • entry_class (Class)

    The parser associated entry class for the work/collection/file_set.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/parsers/bulkrax/parser_export_record_set.rb', line 81

def each
  counter = 0

  works.each do |work|
    break if limit_reached?(limit, counter)
    yield(work.fetch('id'), work_entry_class)
    counter += 1
  end

  return if limit_reached?(limit, counter)

  collections.each do |collection|
    break if limit_reached?(limit, counter)
    yield(collection.fetch('id'), collection_entry_class)
    counter += 1
  end

  return if limit_reached?(limit, counter)

  file_sets.each do |file_set|
    break if limit_reached?(limit, counter)
    yield(file_set.fetch('id'), file_set_entry_class)
    counter += 1
  end
end