Skip to content

Commit

Permalink
Some refactoring based on technique used in the previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fixlr committed Mar 4, 2010
1 parent 145ae23 commit deca751
Showing 1 changed file with 13 additions and 43 deletions.
56 changes: 13 additions & 43 deletions lib/wcapi/record.rb
Expand Up @@ -46,66 +46,36 @@ def subjects
end

def isbns
unless @isbns
@isbns = []
xpath_all(@doc, "datafield[@tag='020']/subfield[@code='a']").each do |i|
@isbns << WCAPI::Record::ISBN.new(xpath_get_text(i))
end
@isbns ||= xpath_all(@doc, "datafield[@tag='020']/subfield[@code='a']").collect do |i|
WCAPI::Record::ISBN.new(xpath_get_text(i))
end
return @isbns
end

def link
"http://www.worldcat.org/oclc/#{self.oclc_id}"
end

def title
unless @title
@title = []
xpath_all(@doc, "datafield[@tag='245']/subfield[@code='a']").each do |i|
@title << xpath_get_text(i)
end
xpath_all(@doc, "datafield[@tag='245']/subfield[@code='b']").each do |i|
@title << xpath_get_text(i)
end
@title ||= ['a', 'b'].collect do |code|
xpath_get_text(xpath_first(@doc, "datafield[@tag='245']/subfield[@code='#{code}']"))
end
return @title
end

def authors
unless @authors
@authors = []
xpath_all(@doc, "datafield[@tag='100']/subfield[@code='a']").each do |i|
@authors << xpath_get_text(i)
end
xpath_all(@doc, "datafield[@tag='110']/subfield[@code='a']").each do |i|
@authors << xpath_get_text(i)
end
xpath_all(@doc, "datafield[@tag='111']/subfield[@code='a']").each do |i|
@authors << xpath_get_text(i)
end

xpath_all(@doc, "datafield[@tag='700']/subfield[@code='a']").each do |i|
@authors << xpath_get_text(i)
end
xpath_all(@doc, "datafield[@tag='710']/subfield[@code='a']").each do |i|
@authors << xpath_get_text(i)
end
xpath_all(@doc, "datafield[@tag='711']/subfield[@code='a']").each do |i|
@authors << xpath_get_text(i)
end
@authors ||= ['100', '110', '111', '700', '710', '711'].collect do |tag|
xpath_get_text(xpath_first(@doc, "datafield[@tag='#{tag}']/subfield[@code='a']"))
end
return @authors
end

def summary
unless @summary
if xpath_first(@doc, "datafield[@tag='520']") != nil
@summary = xpath_get_text(xpath_first(@doc, "datafield[@tag='520']/subfield[@code='a']"))
elsif xpath_first(@doc, "datafield[@tag='500']") != nil
@summary = xpath_get_text(xpath_first(@doc, "datafield[@tag='500']/subfield[@code='a']"))
else
@summary = ''
@summary ||= '' # default empty string

# Check for both 500 and 520, but give preference to the 520
['500', '520'].each do |tag|
if xpath_first(@doc, "datafield[@tag='#{tag}']") != nil
@summary = xpath_get_text(xpath_first(@doc, "datafield[@tag='#{tag}']/subfield[@code='a']"))
end
end
end
return @summary
Expand Down

0 comments on commit deca751

Please sign in to comment.