File: litdb.rb

package info (click to toggle)
bioruby 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,328 kB
  • ctags: 7,787
  • sloc: ruby: 61,539; xml: 3,383; makefile: 58; sh: 4
file content (92 lines) | stat: -rw-r--r-- 1,478 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#
# = bio/db/litdb.rb - LITDB database class
#
# Copyright::  Copyright (C) 2001 Toshiaki Katayama <k@bioruby.org>
# License::    The Ruby License
#
# $Id:$
#

require 'bio/db'

module Bio

  # = LITDB class
  class LITDB < NCBIDB

    # Delimiter
    DELIMITER = "\nEND\n"

    # Delimiter
    RS = DELIMITER

    #
    TAGSIZE = 12

    #
    def initialize(entry)
      super(entry, TAGSIZE)
    end

    # Returns
    def reference
      hash = Hash.new('') 

      hash['authors'] = author.split(/;/).map {|x| x.sub(/,/, ', ')}
      hash['title']   = title 
      hash['journal'] = journal.gsub(/\./, '. ').strip

      vol = volume.split(/,\s+/)
      if vol.size > 1
        hash['volume'] = vol.shift.sub(/Vol\./, '')
        hash['pages'],
        hash['year'] = vol.pop.split(' ')
        hash['issue'] = vol.shift.sub(/No\./, '') unless vol.empty?
      end

      return Reference.new(hash) 
    end

    # CODE
    def entry_id
      field_fetch('CODE')
    end

    # TITLE
    def title
      field_fetch('TITLE')
    end

    # FIELD
    def field
      field_fetch('FIELD')
    end

    # JOURNAL
    def journal
      field_fetch('JOURNAL')
    end

    # VOLUME
    def volume
      field_fetch('VOLUME')
    end

    # KEYWORD ';;'
    def keyword
      unless @data['KEYWORD']
        @data['KEYWORD'] = fetch('KEYWORD').split(/;;\s*/)
      end
      @data['KEYWORD']
    end

    # AUTHOR
    def author
      field_fetch('AUTHOR')
    end

  end

end