ruby-oai 0.0.3 — thanks ed
Ed posted revisions to the ruby-oai package. It includes the ability to utilize libxml as the xml parser.
For those interested, this can now be coupled with the following class to parse a normal dublin core unqualified record into an object version of the record. BTW, I realize that this code makes some use of the eval function — probably one that you want to general avoid — but is a very powerful function when one needs to execute dynamic code.
require 'xml/libxml'
require 'oai'
class OaiDc
attr_accessor :title, :creator, :subject, :description, :publisher,
:relation, :date, :type, :format, :contributor,
:identifier, :source, :language, :coverage, :rights
def parse_metadata(element)
labels = self.metadata_list()
if element == nil: return nil end
labels.each do |item|
x = 0
tmp_element = element.metadata.find("./oai_dc:dc/" + item, ["oai_dc:http://www.openarchives.org/OAI/2.0/oai_dc/","dc:http://purl.org/dc/elements/1.1/"])
item = item.gsub('dc:','')
eval("@" + item + " = []")
tmp_element.each do |i|
s = i.content
if s != nil
eval("@" + item + "[" + x.to_s + '] = ' + s.dump )
x += 1
end
end
if x==0: eval('@' + item + '[' + x.to_s + '] = nil') end
end
end
def metadata_list()
labels = ['dc:title','dc:creator',
'dc:subject','dc:description',
'dc:publisher','dc:relation',
'dc:date','dc:type','dc:format',
'dc:contributor','dc:identifier',
'dc:source','dc:language',
'dc:coverage','dc:rights']
end
end
No comments yet.
Leave a comment
Categories
- Access 2006
- ALA Midwinter 2007
- ALA Summer 2007
- Book
- C#
- Code4Lib 2007
- Code4Lib2008
- Conferences
- CONTENTdm
- Cycling
- Digital Libraries
- Dspace
- Education
- Family
- General Computing
- Innovative Interfaces
- Java
- LibraryFind
- MarcEdit
- Microsoft
- NWIUG 2006
- OAI
- OCLC
- Open Library
- OSCON 2006
- Patent Stupidity
- Programming
- rails
- Readex 2006
- ruby
- Running
- Simpsons
- Travel
- Uncategorized
- Wii
- Wikipedia
Archive
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005