lib/gutenberg_rdf/rdf.rb in gutenberg_rdf-0.2.3 vs lib/gutenberg_rdf/rdf.rb in gutenberg_rdf-0.3.1
- old
+ new
@@ -78,17 +78,35 @@
t = xml.elements['pgterms:ebook/dcterms:title'].text.gsub(/—/, '-')
title_array = t.split(/\n/)
title_array = title_array.first.split(/:/) if title_array.count == 1
title_array = title_array.first.split(/;/) if title_array.count == 1
+ title_array = title_array.first.split(/, or,/) if title_array.count == 1
- title_array.each(&:strip!)
+ title_array.map(&:strip)
end
+ def roles
+ @roles ||= extract_roles
+ end
+
+ def extract_roles
+ entries = Hash.new
+ xml.elements.each('pgterms:ebook/dcterms:creator') do |entry|
+ entries["#{entry.attributes['rdf:resource'].sub('2009/agents/', '')}"] = 'aut'
+ end
+ xml.elements.each('pgterms:ebook/marcrel:*') do |entry|
+ entries["#{entry.attributes['rdf:resource'].sub('2009/agents/', '')}"] = entry.name
+ end
+ entries
+ end
+
def extract_authors
entries = Array.new
xml.elements.each('pgterms:agent') do |agent|
- entries << Agent.new(agent)
+ entry = Agent.new(agent)
+ entry.assign_role(roles)
+ entries << entry
end
entries
end
def official_cover_images