Module: Sufia::GenericFile::Export

Included in:
Sufia::GenericFile
Defined in:
app/models/concerns/sufia/generic_file/export.rb

Instance Method Summary collapse

Instance Method Details

#export_as_apa_citationObject



77
78
79
80
81
82
83
84
85
86
87
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
# File 'app/models/concerns/sufia/generic_file/export.rb', line 77

def export_as_apa_citation
  text = ''
  authors_list = []
  authors_list_final = []

  # setup formatted author list
  authors = author_list
  authors.each do |author|
    next if author.blank?
    authors_list.push(abbreviate_name(author))
  end
  authors_list.each do |author|
    if author == authors_list.first # first
      authors_list_final.push(author.strip)
    elsif author == authors_list.last # last
      authors_list_final.push(", & " + author.strip)
    else # all others
      authors_list_final.push(", " + author.strip)
    end
  end
  text << authors_list_final.join
  unless text.blank?
    if text[-1, 1] != "."
      text << ". "
    else
      text << " "
    end
  end
  # Get Pub Date
  text << "(" + setup_pub_date + "). " unless setup_pub_date.nil?

  # setup title info
  title_info = setup_title_info
  text << "<i>" + title_info + "</i> " unless title_info.nil?

  # Publisher info
  text << setup_pub_info unless setup_pub_info.nil?
  text += "." if text[-1, 1] != "." unless text.blank?
  text.html_safe
end

#export_as_chicago_citationObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'app/models/concerns/sufia/generic_file/export.rb', line 159

def export_as_chicago_citation
  author_text = ""
  authors = all_authors
  unless authors.blank?
    if authors.length > 10
      authors.each_with_index do |author, index|
        if index < 7
          if index == 0
            author_text << "#{author}"
            if author.ends_with?(",")
              author_text << " "
            else
              author_text << ", "
            end
          else
            author_text << "#{name_reverse(author)}, "
          end
        end
      end
      author_text << " et al."
    elsif authors.length > 1
      authors.each_with_index do |author, index|
        if index == 0
          author_text << "#{author}"
          if author.ends_with?(",")
            author_text << " "
          else
            author_text << ", "
          end
        elsif index + 1 == authors.length
          author_text << "and #{name_reverse(author)}."
        else
          author_text << "#{name_reverse(author)}, "
        end
      end
    else
      author_text << authors.first
    end
  end
  title_info = ""
  title_info << citation_title(clean_end_punctuation(CGI.escapeHTML(title.first)).strip) unless title.blank?

  pub_info = ""
  place = based_near.first
  publisher = self.publisher.first
  unless place.blank?
    place = CGI.escapeHTML(place)
    pub_info << place
    pub_info << ": " unless publisher.blank?
  end
  unless publisher.blank?
    publisher = CGI.escapeHTML(publisher)
    pub_info << publisher
    pub_info << ", " unless setup_pub_date.nil?
  end
  pub_info << setup_pub_date unless setup_pub_date.nil?

  citation = ""
  citation << "#{author_text} " unless author_text.blank?
  citation << "<i>#{title_info}.</i> " unless title_info.blank?
  citation << "#{pub_info}." unless pub_info.blank?
  citation.html_safe
end

#export_as_endnoteObject

MIME: ‘application/x-endnote-refer’



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/concerns/sufia/generic_file/export.rb', line 5

def export_as_endnote
  end_note_format = {
    '%T' => [:title, ->(x) { x.first }],
    '%Q' => [:title, ->(x) { x.drop(1) }],
    '%A' => [:creator],
    '%C' => [:publication_place],
    '%D' => [:date_created],
    '%8' => [:date_uploaded],
    '%E' => [:contributor],
    '%I' => [:publisher],
    '%J' => [:series_title],
    '%@' => [:isbn],
    '%U' => [:related_url],
    '%7' => [:edition_statement],
    '%R' => [:persistent_url],
    '%X' => [:description],
    '%G' => [:language],
    '%[' => [:date_modified],
    '%9' => [:resource_type],
    '%~' => I18n.t('sufia.product_name'),
    '%W' => I18n.t('sufia.institution_name')
  }
  text = []
  text << "%0 GenericFile"
  end_note_format.each do |endnote_key, mapping|
    if mapping.is_a? String
      values = [mapping]
    else
      values = send(mapping[0]) if self.respond_to? mapping[0]
      values = mapping[1].call(values) if mapping.length == 2
      values = Array(values)
    end
    next if values.empty? || values.first.nil?
    spaced_values = values.join("; ")
    text << "#{endnote_key} #{spaced_values}"
  end
  text.join("\n")
end

#export_as_mla_citationObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'app/models/concerns/sufia/generic_file/export.rb', line 118

def export_as_mla_citation
  text = ''
  authors_final = []

  # setup formatted author list
  authors = author_list

  if authors.length < 4
    authors.each do |author|
      if author == authors.first # first
        authors_final.push(author)
      elsif author == authors.last # last
        authors_final.push(", and " + name_reverse(author) + ".")
      else # all others
        authors_final.push(", " + name_reverse(author))
      end
    end
    text << authors_final.join
    unless text.blank?
      if text[-1, 1] != "."
        text << ". "
      else
        text << " "
      end
    end
  else
    text << authors.first + ", et al. "
  end
  # setup title
  title_info = setup_title_info
  text << "<i>" + mla_citation_title(title_info) + "</i> " unless title.blank?

  # Publication
  text << setup_pub_info + ", " unless setup_pub_info.nil?

  # Get Pub Date
  text << setup_pub_date unless setup_pub_date.nil?
  text << "." unless text.blank? if text[-1, 1] != "."
  text.html_safe
end

#export_as_openurl_ctx_kevObject

MIME type: ‘application/x-openurl-ctx-kev’



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/concerns/sufia/generic_file/export.rb', line 49

def export_as_openurl_ctx_kev
  export_text = []
  export_text << "url_ver=Z39.88-2004&ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator"
  field_map = {
    title: 'title',
    creator: 'creator',
    subject: 'subject',
    description: 'description',
    publisher: 'publisher',
    contributor: 'contributor',
    date_created: 'date',
    resource_type: 'format',
    identifier: 'identifier',
    language: 'language',
    tag: 'relation',
    based_near: 'coverage',
    rights: 'rights'
  }
  field_map.each do |element, kev|
    values = send(element)
    next if values.empty? || values.first.nil?
    values.each do |value|
      export_text << "rft.#{kev}=#{CGI.escape(value.to_s)}"
    end
  end
  export_text.join('&') unless export_text.blank?
end

#persistent_urlObject



44
45
46
# File 'app/models/concerns/sufia/generic_file/export.rb', line 44

def persistent_url
  "#{Sufia.config.persistent_hostpath}#{id}"
end