Sha256: e55d18081dda8152e433ef0c45cf98fefed3e09963e93a2bd87714a0f9b3d362

Contents?: true

Size: 685 Bytes

Versions: 1

Compression:

Stored size: 685 Bytes

Contents

require 'forwardable'

module Slaw
  # A collection of Act instances.
  class DocumentCollection

    include Enumerable
    extend Forwardable

    attr_accessor :items

    def_delegators :items, :each, :<<, :length

    def initialize(items=nil)
      @items = items || []
    end

    # Find all XML files in +path+ and return
    # a list of instances of +cls+.
    def discover(path, cls=Slaw::Act)
      for fname in Dir.glob("#{path}/**/*.xml")
        @items << cls.new(fname)
      end
    end

    # Try to find an act who's FRBRuri matches this one,
    # returning nil on failure
    def for_uri(uri)
      return @items.find { |doc| doc.id_uri == uri }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slaw-0.1.2 lib/slaw/collection.rb