Class: Rubyscholar::Formatter
- Inherits:
-
Object
- Object
- Rubyscholar::Formatter
- Defined in:
- lib/rubyscholar-main.rb
Instance Attribute Summary collapse
-
#altmetricDOIs ⇒ Object
Returns the value of attribute altmetricDOIs.
-
#nameToHighlight ⇒ Object
Returns the value of attribute nameToHighlight.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#pdfLinks ⇒ Object
Returns the value of attribute pdfLinks.
Instance Method Summary collapse
-
#initialize(parser, nameToHighlight = nil, pdfLinks = {}, altmetricDOIs = [], minCitationCount = 1) ⇒ Formatter
constructor
A new instance of Formatter.
- #to_html ⇒ Object
Constructor Details
#initialize(parser, nameToHighlight = nil, pdfLinks = {}, altmetricDOIs = [], minCitationCount = 1) ⇒ Formatter
Returns a new instance of Formatter.
80 81 82 83 84 85 86 |
# File 'lib/rubyscholar-main.rb', line 80 def initialize(parser, nameToHighlight = nil, pdfLinks = {}, altmetricDOIs = [], minCitationCount = 1) @parser = parser @nameToHighlight = nameToHighlight @pdfLinks = pdfLinks @altmetricDOIs = altmetricDOIs @minCitations = minCitationCount end |
Instance Attribute Details
#altmetricDOIs ⇒ Object
Returns the value of attribute altmetricDOIs.
78 79 80 |
# File 'lib/rubyscholar-main.rb', line 78 def altmetricDOIs @altmetricDOIs end |
#nameToHighlight ⇒ Object
Returns the value of attribute nameToHighlight.
78 79 80 |
# File 'lib/rubyscholar-main.rb', line 78 def nameToHighlight @nameToHighlight end |
#parser ⇒ Object
Returns the value of attribute parser.
78 79 80 |
# File 'lib/rubyscholar-main.rb', line 78 def parser @parser end |
#pdfLinks ⇒ Object
Returns the value of attribute pdfLinks.
78 79 80 |
# File 'lib/rubyscholar-main.rb', line 78 def pdfLinks @pdfLinks end |
Instance Method Details
#to_html ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/rubyscholar-main.rb', line 88 def to_html builder = Nokogiri::HTML::Builder.new do |doc| doc.div( :class => "publication") { doc.ol { @parser.parsedPapers.each_with_index do |paper, index| doc.li( :value=> ( (@parser.parsedPapers).length - index).to_s) { doc.b paper[:title] + '.' doc.text ' (' + paper[:year] + '). ' if paper[:authors].include?(@nameToHighlight) doc.text( paper[:authors].sub(Regexp.new(@nameToHighlight + '.*'), '') ) doc.span( :class => "label") { doc.text @nameToHighlight } doc.text( paper[:authors].sub(Regexp.new('.*' + @nameToHighlight), '') ) else doc.text( paper[:authors]) + '.' end doc.em ' ' + paper[:journalName] doc.text ' ' + paper[:journalDetails] unless paper[ :doi].empty? doc.text(' ') doc.a( :href => URI.join("http://dx.doi.org/", paper[ :doi])) { doc.text "[DOI]" } end if @pdfLinks.keys.include?(paper[:title]) doc.text(' ') doc.a( :href => @pdfLinks[paper[:title]]) { doc.text "[PDF]" } end if paper[ :citationCount].to_i > @minCitations doc.text(' ') doc.a( :href => paper[ :citingPapers], :title => "Citations") { doc.span( :class => "badge badge-inverse") { doc.test("#{paper[ :citationCount]}x") } } end if altmetricDOIs.include?( paper[ :doi]) doc.text(' ') doc.span( :class => 'altmetric-embed', :'data-badge-popover' => 'bottom', :'data-doi' => paper[ :doi] ) end } end } } end return builder.to_html end |