Class: Eader::Document

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Document

Returns a new instance of Document.



7
8
9
10
# File 'lib/eader/document.rb', line 7

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

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



5
6
7
# File 'lib/eader/document.rb', line 5

def doc
  @doc
end

Instance Method Details

#itemsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/eader/document.rb', line 28

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

#seriesObject



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

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

#subseriesObject



20
21
22
23
24
25
26
# File 'lib/eader/document.rb', line 20

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