Class: Marcxella::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/marcxella/document.rb

Overview

Container for a MARC-XML document

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Document

Constructor for Document object

Parameters:

  • xml (Nokogiri::XML::Document, File, String)

    source

Since:

  • 0.1.0



11
12
13
14
15
16
17
# File 'lib/marcxella/document.rb', line 11

def initialize(xml)
  if xml.is_a? Nokogiri::XML::Document
    @document = xml
  else
    @document = Nokogiri::XML(xml)
  end
end

Instance Attribute Details

#documentNokigiri::XML::Document (readonly)

wrapped Nokogiri document

Returns:

  • (Nokigiri::XML::Document)

    the current value of document

Since:

  • 0.1.0



6
7
8
# File 'lib/marcxella/document.rb', line 6

def document
  @document
end

Instance Method Details

#collectionsArray<Collection>

Collection elements

Returns:

  • (Array<Collection>)

    array of collection objects (possible empty).

Since:

  • 0.1.0



29
30
31
# File 'lib/marcxella/document.rb', line 29

def collections
  @document.css('collection').map{|c| Collection.new(c)}
end

#recordsArray<Record>

Record elements

Returns:

  • (Array<Record>)

    array of record objects (possibly empty). If the document contains collection elements, returns record objects inside the collections

Since:

  • 0.1.0



23
24
25
# File 'lib/marcxella/document.rb', line 23

def records
  @document.css('record').map{|r| Record.new(r)}
end