lib/eader/document.rb in eader-0.0.2 vs lib/eader/document.rb in eader-0.0.3
- old
+ new
@@ -7,17 +7,37 @@
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.css('did'))
+ end
+ end.compact
+ end
+
+ def subseries
+ doc.css('dsc c02').map do |c|
+ if c['level'] == 'subseries'
+ Item.new(c.css('did'))
+ end
+ end.compact
+ end
+
def items
- dsc_levels.map do |d|
- Item.new(d.css('did'))
+ @items ||= []
+
+ (1..3).each do |n|
+ doc.css("dsc c0#{n}").map do |c|
+ if c['level'] == 'item'
+ @items << Item.new(c.css('did'))
+ end
+ end
end
- end
- def dsc_levels
- doc.css('dsc c01')
+ @items.compact
end
private
def xml_doc_class
Nokogiri::XML::Document