Class: PLOS::Article

Inherits:
Object
  • Object
show all
Includes:
XmlHelpers
Defined in:
lib/plos/article.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XmlHelpers

#nodes_to_hash, #parse_node, #tag_value

Constructor Details

#initialize(id, node) ⇒ Article

Returns a new instance of Article.



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
# File 'lib/plos/article.rb', line 19

def initialize(id, node)
  self.id = id
  self.node = node

  self.article_title = tag_value(node.search("title-group"), "article-title")
  self.journal_title = tag_value(node.search("journal-title-group"), "journal-title")

  self.issns = nodes_to_hash(node.search("journal-meta/issn"), "pub-type")
  self.journal_ids = nodes_to_hash(node.search("journal-meta/journal-id"), "journal-id-type")
  self.article_ids = nodes_to_hash(node.search("article-meta/article-id"), "pub-id-type")

  node.search("aff").each do |aff_node|
    self.affiliations << PLOS::Affiliation.new(aff_node)
  end

  node.search("contrib").each do |contrib_node|
    self.contributors << PLOS::Contributor.new(contrib_node)
  end

  node.search("fig").each do |fig_node|
    self.figures << PLOS::Figure.new(fig_node)
  end

  node.search("sec").each do |section_node|
    self.sections << PLOS::Section.new(section_node)
  end

  node.search("ref").each do |ref_node|
    self.references << PLOS::Reference.new(ref_node)
  end

  node.search("named-content").each do |content_node|
    type = content_node.attr("content-type")
    value = content_node.text
    named_content << {:type => type, :value => value}
  end
end

Instance Attribute Details

#affiliationsObject



99
100
101
# File 'lib/plos/article.rb', line 99

def affiliations
  @affiliations ||= []
end

#article_idsObject

Returns the value of attribute article_ids.



8
9
10
# File 'lib/plos/article.rb', line 8

def article_ids
  @article_ids
end

#article_titleObject

Returns the value of attribute article_title.



7
8
9
# File 'lib/plos/article.rb', line 7

def article_title
  @article_title
end

#contributorsObject



103
104
105
# File 'lib/plos/article.rb', line 103

def contributors
  @contributors ||= []
end

#figuresObject



107
108
109
# File 'lib/plos/article.rb', line 107

def figures
  @figures ||= []
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/plos/article.rb', line 6

def id
  @id
end

#issnsObject

Returns the value of attribute issns.



11
12
13
# File 'lib/plos/article.rb', line 11

def issns
  @issns
end

#journal_idsObject

Returns the value of attribute journal_ids.



10
11
12
# File 'lib/plos/article.rb', line 10

def journal_ids
  @journal_ids
end

#journal_titleObject

Returns the value of attribute journal_title.



9
10
11
# File 'lib/plos/article.rb', line 9

def journal_title
  @journal_title
end

#named_contentObject



119
120
121
# File 'lib/plos/article.rb', line 119

def named_content
  @named_content ||= []
end

#nodeObject

Returns the value of attribute node.



5
6
7
# File 'lib/plos/article.rb', line 5

def node
  @node
end

#referencesObject



111
112
113
# File 'lib/plos/article.rb', line 111

def references
  @references ||= []
end

#sectionsObject



115
116
117
# File 'lib/plos/article.rb', line 115

def sections
  @sections ||= []
end

Class Method Details

.base_urlObject



57
58
59
# File 'lib/plos/article.rb', line 57

def self.base_url
  "http://www.plosone.org"
end

.bib_tex_citation_url(id) ⇒ Object



82
83
84
# File 'lib/plos/article.rb', line 82

def self.bib_tex_citation_url(id)
  "#{base_url}/article/getBibTexCitation.action?articleURI=info:doi/#{id}"
end

.citation(id, format = "RIS") ⇒ Object



86
87
88
89
# File 'lib/plos/article.rb', line 86

def self.citation(id, format="RIS")
  url = (format == "RIS" ? PLOS::Article.ris_citation_url(id) : PLOS::Article.bib_tex_citation_url(id))
  RestClient.get(url)
end

.content(id) ⇒ Object



69
70
71
# File 'lib/plos/article.rb', line 69

def self.content(id)
  RestClient.get(self.url(id))
end

.get(id) ⇒ Object



61
62
63
# File 'lib/plos/article.rb', line 61

def self.get(id)
  PLOS::Article.new(id, self.xml(id))
end

.ris_citation_url(id) ⇒ Object



78
79
80
# File 'lib/plos/article.rb', line 78

def self.ris_citation_url(id)
  "#{base_url}/article/getRisCitation.action?articleURI=info:doi/#{id}"
end

.url(id, format = "XML") ⇒ Object



73
74
75
76
# File 'lib/plos/article.rb', line 73

def self.url(id, format="XML")
  # format = "XML|PDF"
  "#{base_url}/article/fetchObjectAttachment.action?uri=info:doi/#{id}&representation=#{format}"
end

.xml(id) ⇒ Object



65
66
67
# File 'lib/plos/article.rb', line 65

def self.xml(id)
  Nokogiri::XML(self.content(id))
end

Instance Method Details

#authorsObject



91
92
93
# File 'lib/plos/article.rb', line 91

def authors
  contributors.collect { |contrib| contrib.name if contrib.type == "author" }.compact
end

#citation(format = "RIS") ⇒ Object



123
124
125
# File 'lib/plos/article.rb', line 123

def citation(format="RIS")
  PLOS::Article.citation(id, format)
end

#editorsObject



95
96
97
# File 'lib/plos/article.rb', line 95

def editors
  contributors.collect { |contrib| contrib.name if contrib.type == "editor" }.compact
end