Sha256: 4bf755933af196e1653d739a13b3b31f7d3001f5126c0f176bd40b12a23f4c02

Contents?: true

Size: 762 Bytes

Versions: 3

Compression:

Stored size: 762 Bytes

Contents

module Metacrunch
  module Marcxml
    class Document
      class DatafieldSet
        include Enumerable

        def initialize(datafields)
          @datafields = datafields || []
        end

        def each(&block)
          @datafields.each(&block)
        end

        def to_a
          @datafields
        end

        def empty?
          @datafields.empty?
        end

        def present?
          !empty?
        end

        # @return [Metacrunch::Marcxml::Document::SubfieldSet]
        def subfields(code = nil)
          subfields = @datafields.map do |datafield|
            datafield.subfields(code).to_a
          end.flatten(1)

          Metacrunch::Marcxml::Document::SubfieldSet.new(subfields)
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
metacrunch-marcxml-3.1.0 lib/metacrunch/marcxml/document/datafield_set.rb
metacrunch-marcxml-3.0.0 lib/metacrunch/marcxml/document/datafield_set.rb
metacrunch-marcxml-2.0.0 lib/metacrunch/marcxml/document/datafield_set.rb