Module: Blacklight::Ris::DocumentExport

Defined in:
app/models/concerns/blacklight/ris/document_export.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(document) ⇒ Object



4
5
6
# File 'app/models/concerns/blacklight/ris/document_export.rb', line 4

def self.extended(document)
  document.will_export_as(:ris, 'application/x-research-info-systems')
end

Instance Method Details

#export_as_risObject



8
9
10
11
12
13
14
15
# File 'app/models/concerns/blacklight/ris/document_export.rb', line 8

def export_as_ris
  ris_hash = to_ris_hash
  lines = ris_hash.keys
    .select { |key| ris_hash[key].present? }
    .flat_map { |key| render_ris_key_value(key, ris_hash[key]) }
  lines << 'ER  - '
  lines.compact.join("\n")
end

#render_ris_key_value(key, val) ⇒ Object



17
18
19
20
21
22
23
# File 'app/models/concerns/blacklight/ris/document_export.rb', line 17

def render_ris_key_value(key, val)
  if val.is_a?(Array)
    val.map { |v| "#{key}  - #{v}" }
  else
    "#{key}  - #{val}"
  end
end

#to_ris_hashObject



25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/concerns/blacklight/ris/document_export.rb', line 25

def to_ris_hash
  h = Hash.new
  self.class.ris_field_mappings.each do |key, val|
    if val.is_a?(Proc)
      h[key] = instance_eval(&val)
    else
      h[key] = fetch(val, '')
    end
  end
  h
end