Sha256: 874a71c34850245814d4e719dfd340d62c6b00eed07be08c194593c4ac70ad50

Contents?: true

Size: 786 Bytes

Versions: 1

Compression:

Stored size: 786 Bytes

Contents

require 'open-uri'

module Eader
   class Document
    attr_reader :doc

    def initialize(path)
      file = open(path)
      @doc = xml_doc_class.parse(file)
    end

    def series
      doc.css('dsc c01').map do |c|
        if c['level'] == 'series'
          Item.new(c)
        end
      end.compact
    end

    def subseries
      doc.css('dsc c02').map do |c|
        if c['level'] == 'subseries'
          Item.new(c)
        end
      end.compact
    end

    def items
      @items ||= []

      (1..3).each do |n|
        doc.css("dsc c0#{n}").map do |c|
          if c['level'] == 'item'
            @items << Item.new(c)
          end
        end
      end

      @items.compact
    end

    private
    def xml_doc_class
      Nokogiri::XML::Document
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eader-0.0.4 lib/eader/document.rb