[BioRuby-cvs] bioruby/lib/bio reference.rb,1.24,1.25

Pjotr Prins pjotr at dev.open-bio.org
Thu May 29 11:25:47 UTC 2008


Update of /home/repository/bioruby/bioruby/lib/bio
In directory dev.open-bio.org:/tmp/cvs-serv15189

Modified Files:
	reference.rb 
Log Message:
- Improved bibtex support (optional output of abstract - strip empty fields)
- Put generated URL into separate method



Index: reference.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/reference.rb,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** reference.rb	5 Apr 2007 23:35:39 -0000	1.24
--- reference.rb	29 May 2008 11:25:44 -0000	1.25
***************
*** 71,77 ****
      attr_reader :abstract
  
-     # An URL String.
-     attr_reader :url
- 
      # MeSH terms in an Array.
      attr_reader :mesh
--- 71,74 ----
***************
*** 128,132 ****
        @medline  = hash['medline'] # 98765432
        @abstract = hash['abstract']
-       @url      = hash['url']
        @mesh     = hash['mesh']
        @affiliations = hash['affiliations']
--- 125,128 ----
***************
*** 232,241 ****
        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|
--- 228,232 ----
        lines << "%P #{@pages}" unless @pages.empty?
        lines << "%M #{@pubmed}" unless @pubmed.to_s.empty?
!       lines << "%U #{url}" unless url.empty?
        lines << "%X #{@abstract}" unless @abstract.empty?
        @mesh.each do |term|
***************
*** 299,318 ****
      # *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
  
--- 290,317 ----
      # *Arguments*:
      # * (optional) _section_: BiBTeX section as String
+     # * (optional) _keywords_: Array of additional keywords, e.g. ['abstract']
      # *Returns*:: String
!     def bibtex(section = nil, add_keywords = [])
        section = "article" unless section
        authors = authors_join(' and ', ' and ')
        pages   = @pages.sub('-', '--')
!       keywords = "author title journal year volume number pages url".split(/ /)
!       bib = "@#{section}{PMID:#{@pubmed},\n"
!       (keywords+add_keywords).each do | kw |
!         if kw == 'author'
!           ref = authors
!         elsif kw == 'title'
!           # strip final dot from title
!           ref = @title.sub(/\.$/,'')
!         elsif kw == 'number'
!           ref = @issue
!         elsif kw == 'url'
!           ref = url
!         else
!           ref = eval('@'+kw)
!         end
!         bib += "  #{kw.ljust(12)} = {#{ref}},\n" if ref != ''
!       end
!       bib+"}\n"
      end
  
***************
*** 500,503 ****
--- 499,513 ----
      end
  
+     # Returns a valid URL for pubmed records
+     #
+     # *Returns*:: String
+     def url
+       if @pubmed != ''
+         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
***************
*** 527,530 ****
--- 537,541 ----
      end
  
+ 
    end
  




More information about the bioruby-cvs mailing list