[BioRuby-cvs] bioruby/lib/bio reference.rb,1.28,1.29
Naohisa Goto
ngoto at dev.open-bio.org
Wed Jun 4 14:56:40 UTC 2008
Update of /home/repository/bioruby/bioruby/lib/bio
In directory dev.open-bio.org:/tmp/cvs-serv1512/lib/bio
Modified Files:
reference.rb
Log Message:
improvement of Bio::Reference#bibtex method
Index: reference.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/reference.rb,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** reference.rb 2 Jun 2008 09:47:08 -0000 1.28
--- reference.rb 4 Jun 2008 14:56:37 -0000 1.29
***************
*** 167,184 ****
# *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 'endnote'
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
--- 167,184 ----
# *Arguments*:
# * (optional) _style_: String with style identifier
! # * (optional) _options_: Options for styles accepting one
# *Returns*:: String
! def format(style = nil, *options)
case style
when 'endnote'
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
***************
*** 295,314 ****
# *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
--- 295,340 ----
# *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
More information about the bioruby-cvs
mailing list