[BioRuby-cvs] bioruby/lib/bio reference.rb,1.24.2.6,1.24.2.7
Naohisa Goto
ngoto at dev.open-bio.org
Tue Jun 17 12:23:52 UTC 2008
Update of /home/repository/bioruby/bioruby/lib/bio
In directory dev.open-bio.org:/tmp/cvs-serv20065/lib/bio
Modified Files:
Tag: BRANCH-biohackathon2008
reference.rb
Log Message:
merged changes in trunk (revision 1.30)
Index: reference.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/reference.rb,v
retrieving revision 1.24.2.6
retrieving revision 1.24.2.7
diff -C2 -d -r1.24.2.6 -r1.24.2.7
*** reference.rb 23 Apr 2008 18:52:18 -0000 1.24.2.6
--- reference.rb 17 Jun 2008 12:23:49 -0000 1.24.2.7
***************
*** 180,186 ****
# *Arguments*:
# * (optional) _style_: String with style identifier
! # * (optional) _option_: Option for styles accepting one
# *Returns*:: String
! def format(style = nil, option = nil)
case style
when 'embl'
--- 180,186 ----
# *Arguments*:
# * (optional) _style_: String with style identifier
! # * (optional) _options_: Options for styles accepting one
# *Returns*:: String
! def format(style = nil, *options)
case style
when 'embl'
***************
*** 189,199 ****
return endnote
when 'bibitem'
! return bibitem(option)
when 'bibtex'
! return bibtex(option)
when 'rd'
! return rd(option)
when /^nature$/i
! return nature(option)
when /^science$/i
return science
--- 189,199 ----
return endnote
when 'bibitem'
! return bibitem(*options)
when 'bibtex'
! return bibtex(*options)
when 'rd'
! return rd(*options)
when /^nature$/i
! return nature(*options)
when /^science$/i
return science
***************
*** 247,256 ****
lines << "%P #{@pages}" unless @pages.empty?
lines << "%M #{@pubmed}" unless @pubmed.to_s.empty?
! if @pubmed
! cgi = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi"
! opts = "cmd=Retrieve&db=PubMed&dopt=Citation&list_uids"
! @url = "#{cgi}?#{opts}=#{@pubmed}"
! end
! lines << "%U #{@url}" unless @url.empty?
lines << "%X #{@abstract}" unless @abstract.empty?
@mesh.each do |term|
--- 247,252 ----
lines << "%P #{@pages}" unless @pages.empty?
lines << "%M #{@pubmed}" unless @pubmed.to_s.empty?
! u = @url.empty? ? pubmed_url : @url
! lines << "%U #{u}" unless u.empty?
lines << "%X #{@abstract}" unless @abstract.empty?
@mesh.each do |term|
***************
*** 289,292 ****
--- 285,290 ----
# {\em Theor. J. Hoge}, 12(3):123--145, 2001.
# ---
+ # *Arguments*:
+ # * (optional) _item_: label string (default: <tt>"PMID:#{pubmed}"</tt>).
# *Returns*:: String
def bibitem(item = nil)
***************
*** 332,351 ****
# *Arguments*:
# * (optional) _section_: BiBTeX section as String
# *Returns*:: String
! def bibtex(section = nil)
section = "article" unless section
authors = authors_join(' and ', ' and ')
! pages = @pages.sub('-', '--')
! return <<-"END".gsub(/\t/, '')
! @#{section}{PMID:#{@pubmed},
! author = {#{authors}},
! title = {#{@title}},
! journal = {#{@journal}},
! year = {#{@year}},
! volume = {#{@volume}},
! number = {#{@issue}},
! pages = {#{pages}},
! }
! END
end
--- 330,375 ----
# *Arguments*:
# * (optional) _section_: BiBTeX section as String
+ # * (optional) _label_: Label string cited by LaTeX documents.
+ # Default is <tt>"PMID:#{pubmed}"</tt>.
+ # * (optional) _keywords_: Hash of additional keywords,
+ # e.g. { 'abstract' => 'This is abstract.' }.
+ # You can also override default keywords.
+ # To disable default keywords, specify false as
+ # value, e.g. { 'url' => false, 'year' => false }.
# *Returns*:: String
! def bibtex(section = nil, label = nil, keywords = {})
section = "article" unless section
authors = authors_join(' and ', ' and ')
! thepages = pages.to_s.empty? ? nil : pages.sub(/\-/, '--')
! unless label then
! label = "PMID:#{pubmed}"
! end
! theurl = if !(url.to_s.empty?) then
! url
! elsif pmurl = pubmed_url and !(pmurl.to_s.empty?) then
! pmurl
! else
! nil
! end
! hash = {
! 'author' => authors.empty? ? nil : authors,
! 'title' => title.to_s.empty? ? nil : title,
! 'number' => issue.to_s.empty? ? nil : issue,
! 'pages' => thepages,
! 'url' => theurl
! }
! keys = %w( author title journal year volume number pages url )
! keys.each do |k|
! hash[k] = self.__send__(k.intern) unless hash.has_key?(k)
! end
! hash.merge!(keywords) { |k, v1, v2| v2.nil? ? v1 : v2 }
! bib = [ "@#{section}{#{label}," ]
! keys.concat((hash.keys - keys).sort)
! keys.each do |kw|
! ref = hash[kw]
! bib.push " #{kw.ljust(12)} = {#{ref}}," if ref
! end
! bib.push "}\n"
! return bib.join("\n")
end
***************
*** 533,536 ****
--- 557,571 ----
end
+ # Returns a valid URL for pubmed records
+ #
+ # *Returns*:: String
+ def pubmed_url
+ unless @pubmed.to_s.empty?
+ cgi = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi"
+ opts = "cmd=Retrieve&db=PubMed&dopt=Citation&list_uids"
+ return "#{cgi}?#{opts}=#{@pubmed}"
+ end
+ ''
+ end
private
More information about the bioruby-cvs
mailing list