class MARC::FieldMap
The FieldMap is an Array of DataFields and Controlfields. It also contains a Hash representation of the fields for faster lookups (under certain conditions)
Attributes
clean[RW]
Public Class Methods
new()
click to toggle source
# File lib/marc/record.rb, line 9 def initialize @tags = {} @clean = true end
Public Instance Methods
each_by_tag(tags) { |tag| ... }
click to toggle source
Returns an array of fields, in the order they appear, according to their tag. The tags argument can be a string (e.g. '245'), an array (['100','700','800']) or a range (('600'..'699')).
# File lib/marc/record.rb, line 34 def each_by_tag(tags) reindex unless @clean indices = @tags.values_at(*(@tags.keys & [*tags])).flatten.sort return [] if indices.empty? self.values_at(*indices).each do |tag| yield tag end end
freeze()
click to toggle source
Freeze for immutability, first reindexing if needed. A frozen FieldMap is safe for concurrent access, and also can more easily avoid accidental reindexing on even read-only use.
Calls superclass method
# File lib/marc/record.rb, line 46 def freeze self.reindex unless @clean super end
reindex()
click to toggle source
Rebuild the HashWithChecksumAttribute with the current values of the fields Array
# File lib/marc/record.rb, line 16 def reindex @tags = {} self.each_with_index do |field, i| @tags[field.tag] ||= [] @tags[field.tag] << i end @clean = true end
tag_list()
click to toggle source
Returns an array of all of the tags that appear in the record (not in the order they appear, however).
# File lib/marc/record.rb, line 26 def tag_list reindex unless @clean @tags.keys end