Class: Pubmedly::Parsers::Article
- Inherits:
-
Object
- Object
- Pubmedly::Parsers::Article
- Defined in:
- lib/pubmedly/parsers/article.rb
Overview
The Article class provides methods to access Article data.
Instance Attribute Summary collapse
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
- #abstract ⇒ Object
- #authors ⇒ Object
- #first_author ⇒ Object
-
#initialize(xml) ⇒ Article
constructor
A new instance of Article.
- #last_author ⇒ Object
- #pmid ⇒ Object
- #publication_date ⇒ Object
- #title ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(xml) ⇒ Article
Returns a new instance of Article.
12 13 14 |
# File 'lib/pubmedly/parsers/article.rb', line 12 def initialize(xml) @xml = xml end |
Instance Attribute Details
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
10 11 12 |
# File 'lib/pubmedly/parsers/article.rb', line 10 def xml @xml end |
Instance Method Details
#abstract ⇒ Object
33 34 35 |
# File 'lib/pubmedly/parsers/article.rb', line 33 def abstract @xml.xpath(".//Abstract").text end |
#authors ⇒ Object
37 38 39 40 41 |
# File 'lib/pubmedly/parsers/article.rb', line 37 def @xml.xpath(".//Author").map do || "#{.xpath(".//LastName").text}, #{.xpath(".//ForeName").text}" end end |
#first_author ⇒ Object
43 44 45 |
# File 'lib/pubmedly/parsers/article.rb', line 43 def .first end |
#last_author ⇒ Object
47 48 49 |
# File 'lib/pubmedly/parsers/article.rb', line 47 def .last end |
#pmid ⇒ Object
51 52 53 54 |
# File 'lib/pubmedly/parsers/article.rb', line 51 def pmid id = @xml.xpath(".//PMID").text.to_i id.zero? ? nil : id end |
#publication_date ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/pubmedly/parsers/article.rb', line 24 def publication_date date_str = @xml.xpath(".//PubDate").text begin date_str.empty? ? "" : Date.parse(date_str) rescue Date::Error Date.strptime(date_str.strip, "%Y") end end |
#title ⇒ Object
20 21 22 |
# File 'lib/pubmedly/parsers/article.rb', line 20 def title @xml.xpath(".//ArticleTitle").text end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/pubmedly/parsers/article.rb', line 16 def to_s "#{.first.split(",").first} (#{publication_date.year}) #{title}" end |