lib/metacrunch/marcxml/record.rb
#
# Returns the data fields matching the given tag(s) and/or ind1/ind2.
#
# @param tag [String, Integer, #each, nil] filter by tag(s). Can be `nil`
#   to match all data fields. The tag can be a string or an integer. To filter for
#   more than a single tag, `tag` also accepts any object that responds to `#each` like
#   `Array` and `Range`.
# @param ind1 [nil, String, Array<String>] filter by indicator 1. Can be nil to match
#   any indicator.
# @param ind2 [nil, String, Array<String>] filter by indicator 2. Can be nil to match
#   any indicator.
#
# @return [Metacrunch::Marcxml::Record::DatafieldSet] Set of data fields matching the
#  given tag(s) and ind1/ind2. The set is empty if a matching field doesn't exist.
#
Returns the data fields matching the given tag(s) and/or ind1/ind2.
Returns the data fields matching the given tag ( s ) and / or ind1 / ind2 .
def datafields(tag = nil, ind1: nil, ind2: nil)
        matched_datafields = if tag.nil?
          @datafields_map.values.flatten(1)
        elsif tag.is_a?(Enumerable)
          tag.map{ |_tag| @datafields_map[normalize_tag(_tag)] }.compact.flatten(1)
        else
          @datafields_map[normalize_tag(tag)]
        end
        matched_datafields = (matched_datafields || []).select do |datafield|
          match_indicator(ind1, datafield.ind1) && match_indicator(ind2, datafield.ind2)
        end
        DatafieldSet.new(matched_datafields)
      end
def datafields ( tag = nil , ind1 : nil , ind2 : nil ) matched_datafields = if tag . nil? @datafields_map . values . flatten ( 1 ) elsif tag . is_a? ( Enumerable ) tag . map { | _tag | @datafields_map [ normalize_tag ( _tag ) ] } . compact . flatten ( 1 ) else @datafields_map [ normalize_tag ( tag ) ] end matched_datafields = ( matched_datafields || [ ] ) . select do | datafield | match_indicator ( ind1 , datafield . ind1 ) && match_indicator ( ind2 , datafield . ind2 ) end DatafieldSet . new ( matched_datafields ) end
Returns the data fields matching the given tag(s) and/or ind1/ind2.
Returns the data fields matching the given tag ( s ) and / or ind1 / ind2 .
Set of data fields matching the given tag(s) and ind1/ind2. The set is empty if a matching field doesn't exist.
Set of data fields matching the given tag ( s ) and ind1 / ind2 . The set is empty if a matching field doesn ' t exist .
Metacrunch::Marcxml::Record::DatafieldSet
tag
filter by tag(s). Can be `nil` to match all data fields. The tag can be a string or an integer. To filter for more than a single tag, `tag` also accepts any object that responds to `#each` like `Array` and `Range`.
filter by tag ( s ) . Can be ` nil ` to match all data fields . The tag can be a string or an integer . To filter for more than a single tag ` tag ` also accepts any object that responds to ` #each ` like ` Array ` and ` Range ` .
ind1
filter by indicator 1. Can be nil to match any indicator.
filter by indicator 1 . Can be nil to match any indicator .
ind2
filter by indicator 2. Can be nil to match any indicator.
filter by indicator 2 . Can be nil to match any indicator .