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

Pjotr Prins pjotr2008 at thebird.nl
Thu May 29 13:57:20 UTC 2008


The reason was preventing code duplication - url is generated in two
places.

The url method does test for pubmed.

Also, in general it is nice to be able to use reference.url for other
purposes. That does what it says.

Feel free to change it again. I thought it was an improvement. Isn't
that class up for redesign anyway?

Pj.

On Thu, May 29, 2008 at 10:00:30PM +0900, Naohisa GOTO wrote:
> On Thu, 29 May 2008 11:25:47 +0000
> Pjotr Prins <pjotr at dev.open-bio.org> wrote:
> 
> > 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
> 
> I don't agree with the changes about URL because Bio::Reference is
> not only for PubMed data but also for general bibliography reference
> data but your changes about the url is too specific for PubMed.
> 
> -- 
> Naohisa Goto
> ng at bioruby.org / ngoto at gen-info.osaka-u.ac.jp
> 
> > 
> > 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
> >   
> > 
> > _______________________________________________
> > bioruby-cvs mailing list
> > bioruby-cvs at lists.open-bio.org
> > http://lists.open-bio.org/mailman/listinfo/bioruby-cvs
> 
> 
> _______________________________________________
> BioRuby mailing list
> BioRuby at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioruby

-- 
mobile nr: 0651172281 (work)



More information about the BioRuby mailing list