Class: ReferenceKey

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers::TagHelper
Defined in:
app/models/reference_key.rb

Instance Method Summary (collapse)

Constructor Details

- (ReferenceKey) initialize(reference)

A new instance of ReferenceKey



6
7
8
# File 'app/models/reference_key.rb', line 6

def initialize reference
  @reference = reference
end

Instance Method Details



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/reference_key.rb', line 27

def to_link user
  (:span, :class => :reference_key_and_expansion) do
    (:a, to_s, :href => '#', :class => :reference_key) +
    (:span, :class => :reference_key_expansion) do
      content = (:span, Formatters::ReferenceFormatter.format(@reference), class: :reference_key_expansion_text)
      document_link = Formatters::CatalogFormatter.format_reference_document_link @reference, user
      content << document_link if document_link
      content << "<a class=\"goto_reference_link\" target=\"_blank\" href=\"/references?q=#{@reference.id}\">".html_safe
      content << (:img, '', :src => "/images/external_link.png")
      content << "</a>".html_safe
      content.html_safe
    end
  end
end

- (Object) to_s



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/reference_key.rb', line 14

def to_s
  names = @reference.author_names.map &:last_name
  case
  when names.size == 1
    "#{names.first}, "
  when names.size == 2
    "#{names.first} & #{names.second}, "
  else
    string = names[0..-2].join ', '
    string << " & " << names[-1] << ', '
  end << @reference.short_citation_year
end

- (Object) to_taxt



10
11
12
# File 'app/models/reference_key.rb', line 10

def to_taxt
  Taxt.encode_reference @reference
end