module MARCExtensions::FieldMapExtensions
Constants
- VALID_TAGS
Public Instance Methods
each_sorted_by_tag(tags = nil, &block)
click to toggle source
Gets the specified fields in order by tag.
@overload each_sorted_by_tag
(tags, &block)
Yields each specified field. @param tags [String, Enumerable<String>] A tag, range of tags, array of tags, or similar @yieldparam field [MARC::ControlField, MARC::DataField] Each field.
@overload each_sorted_by_tag
(tags)
An enumerator of the specified variable fields, sorted by tag. @param tags [String, Enumerable<String>] A tag, range of tags, array of tags, or similar @return [Enumerator::Lazy<MARC::ControlField, MARC::DataField>] the fields
@overload each_sorted_by_tag
(&block)
Yields all fields, sorted by tag. @yieldparam field [MARC::ControlField, MARC::DataField] Each field.
@overload each_sorted_by_tag
An enumerator of all fields, sorted by tag. @return [Enumerator::Lazy<MARC::ControlField, MARC::DataField>] the fields
# File lib/marc_extensions/field_map.rb, line 23 def each_sorted_by_tag(tags = nil, &block) reindex unless @clean indices_for(tags).map { |i| self[i] }.each(&block) end
Private Instance Methods
all_indices()
click to toggle source
# File lib/marc_extensions/field_map.rb, line 41 def all_indices [].tap do |a| @tags.keys.sort.map do |t| a.concat(@tags[t]) end end end
indices_for(tags)
click to toggle source
# File lib/marc_extensions/field_map.rb, line 31 def indices_for(tags) return all_indices unless tags sorted_tag_array(tags) .lazy # prevent unnecessary allocations .map { |t| @tags[t] } # get indices for each tag .reject(&:nil?) # ignoring any tags we don't have fields for .flat_map { |x| x } # flatten list of indices -- equiv. Array#flatten end
sorted_tag_array(tags)
click to toggle source
# File lib/marc_extensions/field_map.rb, line 49 def sorted_tag_array(tags) return Array(tags) if tags.is_a?(Range) Array(tags).sort end