Class: BibliographicalImporter::BibTex::Record

Inherits:
Object
  • Object
show all
Includes:
CommonRecordAttributes
Defined in:
lib/bibliographical_importer/bibtex.rb

Constant Summary

COMMON_FIELDS =
[:title, :abstract, :journal, :year, :volume, :pages,
:language, :affiliation, :doi, :cited, :url, :author]

Instance Attribute Summary collapse

Attributes included from CommonRecordAttributes

#abstract, #affiliation, #author, #cited, #doi, #id_scopus, #id_wos, #journal, #journal_abbr, #keywords, #keywords_plus, #language, #pages, #references_crossref, #references_scopus, #references_wos, #title, #type, #uid, #url, #volume, #year

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bibtex_value) ⇒ Record

Returns a new instance of Record



69
70
71
72
73
74
75
76
# File 'lib/bibliographical_importer/bibtex.rb', line 69

def initialize(bibtex_value)
  @bv=bibtex_value
  @references_wos=[]
  @references_scopus=[]
  parse_common
  parse_specific
  check_title
end

Instance Attribute Details

#bvObject (readonly)

Returns the value of attribute bv



39
40
41
# File 'lib/bibliographical_importer/bibtex.rb', line 39

def bv
  @bv
end

Class Method Details

.create(bibtex_value) ⇒ Object



47
48
49
50
51
52
# File 'lib/bibliographical_importer/bibtex.rb', line 47

def self.create(bibtex_value)
return nil if bibtex_value.is_a? BibTeX::Error
  type=self.determine_type(bibtex_value)
  klass="Record_#{type.capitalize}".to_sym
  BibliographicalImporter::BibTex.const_get(klass).send(:new, bibtex_value)
end

.determine_type(bibtex_value) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bibliographical_importer/bibtex.rb', line 54

def self.determine_type(bibtex_value)
  if bibtex_value[:source].to_s=="Scopus"
    type=:scopus
  elsif bibtex_value["unique-id"].to_s=~/ISI:/
    type=:wos
  elsif bibtex_value[:url].to_s=~/search\.ebscohost.com/
    type=:ebscohost
  elsif bibtex_value[:url].to_s=~/scielo/
    type=:scielo
  else
    type=:generic
  end
  type
end

Instance Method Details

#authorsObject



84
85
86
# File 'lib/bibliographical_importer/bibtex.rb', line 84

def authors
  @bv[:author].to_a
end

#check_titleObject

I don't understand why, but Scopus and Mendelay adds extra {} at titles. Better remove it



98
99
100
101
102
# File 'lib/bibliographical_importer/bibtex.rb', line 98

def check_title
  if title=~/^{(.+)}+/
    @title=$1
  end
end

#parse_commonObject



78
79
80
81
82
# File 'lib/bibliographical_importer/bibtex.rb', line 78

def parse_common
  COMMON_FIELDS.each do |t|
    send("#{t}=", strip_lines(@bv[t].to_s))
  end
end

#parse_specificObject

Determine the type of the reference. It could be infered by fields



90
91
92
# File 'lib/bibliographical_importer/bibtex.rb', line 90

def parse_specific

end

#strip_lines(value) ⇒ Object



94
95
96
# File 'lib/bibliographical_importer/bibtex.rb', line 94

def strip_lines(value)
  value.to_s.gsub(/\n\s*/, ' ')
end