Class: Slaw::DocumentCollection
- Inherits:
-
Object
- Object
- Slaw::DocumentCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/slaw/collection.rb
Overview
A collection of Act instances.
This is useful for looking up acts by their FRBR uri and for loading a collection of XML act documents.
This collection is enumerable and can be iterated over. Use #items to access the underlying array of objects.
Instance Attribute Summary collapse
-
#items ⇒ Object
- Array<Act>
-
The underlying array of acts.
Instance Method Summary collapse
-
#discover(path, cls = Slaw::Act) ⇒ DocumentCollection
Find all XML files in ‘path` and add them into this collection.
-
#for_uri(uri) ⇒ Act?
Try to find an act who’s FRBRuri matches this one, returning nil on failure.
-
#initialize(items = nil) ⇒ DocumentCollection
constructor
A new instance of DocumentCollection.
Constructor Details
#initialize(items = nil) ⇒ DocumentCollection
Returns a new instance of DocumentCollection.
31 32 33 |
# File 'lib/slaw/collection.rb', line 31 def initialize(items=nil) @items = items || [] end |
Instance Attribute Details
#items ⇒ Object
- Array<Act>
-
The underlying array of acts
27 28 29 |
# File 'lib/slaw/collection.rb', line 27 def items @items end |
Instance Method Details
#discover(path, cls = Slaw::Act) ⇒ DocumentCollection
Find all XML files in ‘path` and add them into this collection.
42 43 44 45 46 47 48 |
# File 'lib/slaw/collection.rb', line 42 def discover(path, cls=Slaw::Act) for fname in Dir.glob("#{path}/**/*.xml") @items << cls.new(fname) end self end |
#for_uri(uri) ⇒ Act?
Try to find an act who’s FRBRuri matches this one, returning nil on failure
56 57 58 |
# File 'lib/slaw/collection.rb', line 56 def for_uri(uri) return @items.find { |doc| doc.id_uri == uri } end |