sufia-models 6.2.0 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/app/actors/sufia/generic_file/actor.rb +4 -7
  3. data/app/jobs/active_fedora_id_based_job.rb +1 -1
  4. data/app/jobs/active_fedora_pid_based_job.rb +1 -2
  5. data/app/jobs/audit_job.rb +1 -1
  6. data/app/jobs/batch_update_job.rb +6 -6
  7. data/app/jobs/create_derivatives_job.rb +2 -3
  8. data/app/jobs/import_url_job.rb +8 -5
  9. data/app/jobs/ingest_local_file_job.rb +1 -1
  10. data/app/models/batch.rb +15 -21
  11. data/app/models/checksum_audit_log.rb +0 -1
  12. data/app/models/concerns/sufia/ability.rb +5 -0
  13. data/app/models/concerns/sufia/collection_behavior.rb +3 -2
  14. data/app/models/concerns/sufia/file_stat_utils.rb +19 -21
  15. data/app/models/concerns/sufia/generic_file/batches.rb +1 -3
  16. data/app/models/concerns/sufia/generic_file/characterization.rb +11 -16
  17. data/app/models/concerns/sufia/generic_file/content.rb +0 -1
  18. data/app/models/concerns/sufia/generic_file/derivatives.rb +2 -2
  19. data/app/models/concerns/sufia/generic_file/export.rb +50 -59
  20. data/app/models/concerns/sufia/generic_file/full_text_indexing.rb +15 -18
  21. data/app/models/concerns/sufia/generic_file/metadata.rb +0 -2
  22. data/app/models/concerns/sufia/generic_file/mime_types.rb +9 -9
  23. data/app/models/concerns/sufia/generic_file/permissions.rb +0 -1
  24. data/app/models/concerns/sufia/generic_file/proxy_deposit.rb +0 -1
  25. data/app/models/concerns/sufia/generic_file/querying.rb +9 -5
  26. data/app/models/concerns/sufia/generic_file/trophies.rb +1 -1
  27. data/app/models/concerns/sufia/generic_file/versions.rb +0 -4
  28. data/app/models/concerns/sufia/model_methods.rb +0 -1
  29. data/app/models/concerns/sufia/user.rb +15 -15
  30. data/app/models/concerns/sufia/user_usage_stats.rb +0 -2
  31. data/app/models/datastreams/fits_datastream.rb +25 -25
  32. data/app/models/domain_term.rb +2 -3
  33. data/app/models/featured_work.rb +3 -5
  34. data/app/models/file_download_stat.rb +3 -4
  35. data/app/models/file_usage.rb +10 -11
  36. data/app/models/file_view_stat.rb +3 -3
  37. data/app/models/follow.rb +1 -1
  38. data/app/models/geo_names_resource.rb +3 -3
  39. data/app/models/group.rb +1 -3
  40. data/app/models/local_authority.rb +26 -28
  41. data/app/models/proxy_deposit_request.rb +9 -9
  42. data/app/models/single_use_link.rb +10 -18
  43. data/app/models/sufia/download.rb +2 -2
  44. data/app/models/sufia/pageview.rb +1 -1
  45. data/app/models/trophy.rb +2 -4
  46. data/app/services/sufia/analytics.rb +10 -11
  47. data/app/services/sufia/generic_file_audit_service.rb +11 -12
  48. data/app/services/sufia/repository_audit_service.rb +1 -1
  49. data/config/locales/sufia.en.yml +2 -0
  50. data/lib/generators/sufia/models/abstract_migration_generator.rb +7 -6
  51. data/lib/generators/sufia/models/install_generator.rb +3 -3
  52. data/lib/generators/sufia/models/templates/config/arkivo_constraint.rb +1 -1
  53. data/lib/generators/sufia/models/templates/config/clamav.rb +1 -1
  54. data/lib/generators/sufia/models/templates/config/redis_config.rb +13 -5
  55. data/lib/generators/sufia/models/templates/config/resque_admin.rb +2 -2
  56. data/lib/generators/sufia/models/templates/config/resque_config.rb +1 -1
  57. data/lib/generators/sufia/models/templates/config/sufia.rb +10 -4
  58. data/lib/generators/sufia/models/templates/migrations/create_checksum_audit_logs.rb +1 -1
  59. data/lib/generators/sufia/models/templates/migrations/create_file_download_stats.rb +1 -1
  60. data/lib/generators/sufia/models/templates/migrations/create_file_view_stats.rb +1 -1
  61. data/lib/generators/sufia/models/templates/migrations/create_local_authorities.rb +1 -1
  62. data/lib/generators/sufia/models/update_content_blocks_generator.rb +0 -1
  63. data/lib/generators/sufia/models/upgrade600_generator.rb +0 -1
  64. data/lib/generators/sufia/models/user_stats_generator.rb +2 -2
  65. data/lib/sufia/messages.rb +17 -17
  66. data/lib/sufia/models.rb +1 -1
  67. data/lib/sufia/models/active_fedora/redis.rb +1 -4
  68. data/lib/sufia/models/active_record/redis.rb +2 -3
  69. data/lib/sufia/models/engine.rb +12 -7
  70. data/lib/sufia/models/file_content/versions.rb +0 -1
  71. data/lib/sufia/models/resque.rb +2 -2
  72. data/lib/sufia/models/stats/user_stat_importer.rb +65 -67
  73. data/lib/sufia/models/user_local_directory_behavior.rb +9 -13
  74. data/lib/sufia/models/utils.rb +1 -2
  75. data/lib/sufia/models/version.rb +1 -1
  76. data/lib/sufia/permissions.rb +0 -1
  77. data/lib/sufia/permissions/readable.rb +0 -1
  78. data/lib/sufia/permissions/writable.rb +20 -23
  79. data/lib/tasks/sufia-models_tasks.rake +18 -0
  80. data/sufia-models.gemspec +1 -1
  81. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5e3ced04ed7546efd8a437f75c39d33bd25ef49
4
- data.tar.gz: beb42fc315b7a71f58a87f00492940f0ba57263d
3
+ metadata.gz: e8aaf1e2e42b84b0e4a1331a69fa75380c39b5d8
4
+ data.tar.gz: aa45e5332b4d18964bd006da94f500081a848b46
5
5
  SHA512:
6
- metadata.gz: 3b35bd03100ce61e5d87660b5f10cf7fa0591642859fea090423d170b99af71cea155b4b46f4fd6014c3b98a80e918e5f6cfb64fd86c23579f3ab3629a6fd675
7
- data.tar.gz: dbe7e42f40291485bdb85fa8bb241d0115a29819da55d9155229f0a45b5359f65cc2178e9c7c83c27311657521a8ea6f974eee7a3b5e70e2b5315c853f2965c9
6
+ metadata.gz: 78bd0e47f109f0c8eecfc861458d6ba77726f77ca72f1eb42f2e8969a0fc7409c1f7739b2c1f3c649eb847e658788b45c6cfd0a2c1817ef5c640f3e6e9546ce1
7
+ data.tar.gz: 991b122862009f831320945391d228c1068259b27d1102e44176ed5dea353cb9d366a93b8776f978da8cd0b688c31734247ea1c97267f07fbe03d0c8692d0ae4
@@ -1,7 +1,6 @@
1
1
  module Sufia::GenericFile
2
2
  # Actions are decoupled from controller logic so that they may be called from a controller or a background job.
3
3
  class Actor
4
-
5
4
  attr_reader :generic_file, :user
6
5
 
7
6
  def initialize(generic_file, user)
@@ -73,9 +72,7 @@ module Sufia::GenericFile
73
72
  def destroy
74
73
  generic_file.destroy
75
74
  FeaturedWork.where(generic_file_id: generic_file.id).destroy_all
76
- if Sufia.config.respond_to?(:after_destroy)
77
- Sufia.config.after_destroy.call(generic_file.id, user)
78
- end
75
+ Sufia.config.after_destroy.call(generic_file.id, user) if Sufia.config.respond_to?(:after_destroy)
79
76
  end
80
77
 
81
78
  # Takes an optional block and executes the block if the save was successful.
@@ -93,9 +90,9 @@ module Sufia::GenericFile
93
90
  return false unless generic_file.save
94
91
  rescue RSolr::Error::Http => error
95
92
  ActiveFedora::Base.logger.warn "Sufia::GenericFile::Actor::save_and_record_committer Caught RSOLR error #{error.inspect}"
96
- save_tries+=1
93
+ save_tries += 1
97
94
  # fail for good if the tries is greater than 3
98
- raise error if save_tries >=3
95
+ raise error if save_tries >= 3
99
96
  sleep 0.01
100
97
  retry
101
98
  end
@@ -116,7 +113,7 @@ module Sufia::GenericFile
116
113
  return
117
114
  end
118
115
  scan_result = ClamAV.instance.scanfile(path)
119
- raise Sufia::VirusFoundError.new("A virus was found in #{path}: #{scan_result}") unless scan_result == 0
116
+ raise Sufia::VirusFoundError, "A virus was found in #{path}: #{scan_result}" unless scan_result == 0
120
117
  end
121
118
  end
122
119
 
@@ -17,6 +17,6 @@ class ActiveFedoraIdBasedJob
17
17
  alias_method :generic_file_id, :id
18
18
 
19
19
  def run
20
- raise RuntimeError, "Define #run in a subclass"
20
+ raise "Define #run in a subclass"
21
21
  end
22
22
  end
@@ -1,7 +1,6 @@
1
1
  class ActiveFedoraPidBasedJob < ActiveFedoraIdBasedJob
2
2
  extend Deprecation
3
- def self.extended(document)
3
+ def self.extended(_document)
4
4
  Deprecation.warn ActiveFedoraPidBasedJob, "ActiveFedoraPidBasedJob is deprecated; use ActiveFedoraIdBasedJob instead."
5
5
  end
6
6
  end
7
-
@@ -27,7 +27,7 @@ class AuditJob < ActiveFedoraIdBasedJob
27
27
  login = generic_file.depositor
28
28
  user = User.find_by_user_key(login)
29
29
  logger.warn "User '#{login}' not found" unless user
30
- job_user = User.audituser()
30
+ job_user = User.audituser
31
31
  file_title = generic_file.title.first
32
32
  message = "The audit run at #{log.created_at} for #{file_title} (#{uri}) failed."
33
33
  subject = FAIL
@@ -19,8 +19,8 @@ class BatchUpdateJob
19
19
  end
20
20
 
21
21
  def run
22
- batch = Batch.find_or_create(self.batch_id)
23
- user = User.find_by_user_key(self.login)
22
+ batch = Batch.find_or_create(batch_id)
23
+ user = User.find_by_user_key(login)
24
24
 
25
25
  batch.generic_files.each do |gf|
26
26
  update_file(gf, user)
@@ -43,7 +43,7 @@ class BatchUpdateJob
43
43
  end
44
44
  gf.title = title[gf.id] if title[gf.id]
45
45
  gf.attributes = file_attributes
46
- gf.visibility= visibility
46
+ gf.visibility = visibility
47
47
 
48
48
  save_tries = 0
49
49
  begin
@@ -52,7 +52,7 @@ class BatchUpdateJob
52
52
  save_tries += 1
53
53
  ActiveFedora::Base.logger.warn "BatchUpdateJob caught RSOLR error on #{gf.id}: #{error.inspect}"
54
54
  # fail for good if the tries is greater than 3
55
- raise error if save_tries >=3
55
+ raise error if save_tries >= 3
56
56
  sleep 0.01
57
57
  retry
58
58
  end #
@@ -60,12 +60,12 @@ class BatchUpdateJob
60
60
  saved << gf
61
61
  end
62
62
 
63
- def send_user_success_message user, batch
63
+ def send_user_success_message(user, batch)
64
64
  message = saved.count > 1 ? multiple_success(batch.id, saved) : single_success(batch.id, saved.first)
65
65
  User.batchuser.send_message(user, message, success_subject, false)
66
66
  end
67
67
 
68
- def send_user_failure_message user, batch
68
+ def send_user_failure_message(user, batch)
69
69
  message = denied.count > 1 ? multiple_failure(batch.id, denied) : single_failure(batch.id, denied.first)
70
70
  User.batchuser.send_message(user, message, failure_subject, false)
71
71
  end
@@ -5,9 +5,8 @@ class CreateDerivativesJob < ActiveFedoraIdBasedJob
5
5
 
6
6
  def run
7
7
  return unless generic_file.content.has_content?
8
- if generic_file.video?
9
- return unless Sufia.config.enable_ffmpeg
10
- end
8
+ return if generic_file.video? && !Sufia.config.enable_ffmpeg
9
+
11
10
  generic_file.create_derivatives
12
11
  generic_file.save
13
12
  end
@@ -3,7 +3,6 @@ require 'uri'
3
3
  require 'tempfile'
4
4
 
5
5
  class ImportUrlJob < ActiveFedoraIdBasedJob
6
-
7
6
  def queue_name
8
7
  :import_url
9
8
  end
@@ -11,8 +10,12 @@ class ImportUrlJob < ActiveFedoraIdBasedJob
11
10
  def run
12
11
  user = User.find_by_user_key(generic_file.depositor)
13
12
 
14
- Tempfile.open(id.gsub('/', '_')) do |f|
13
+ Tempfile.open(id.tr('/', '_')) do |f|
15
14
  path, mime_type = copy_remote_file(generic_file.import_url, f)
15
+
16
+ # reload the generic file once the data is copied since this is a long running task
17
+ generic_file.reload
18
+
16
19
  # attach downloaded file to generic file stubbed out
17
20
  if Sufia::GenericFile::Actor.new(generic_file, user).create_content(f, path, 'content', mime_type)
18
21
  # add message to user for downloaded file
@@ -24,12 +27,12 @@ class ImportUrlJob < ActiveFedoraIdBasedJob
24
27
  end
25
28
  end
26
29
 
27
- def copy_remote_file(import_url, f)
30
+ def copy_remote_file(_import_url, f)
28
31
  f.binmode
29
32
  # download file from url
30
33
  uri = URI(generic_file.import_url)
31
34
  http = Net::HTTP.new(uri.host, uri.port)
32
- http.use_ssl = uri.scheme == "https" # enable SSL/TLS
35
+ http.use_ssl = uri.scheme == "https" # enable SSL/TLS
33
36
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
34
37
  mime_type = nil
35
38
 
@@ -43,7 +46,7 @@ class ImportUrlJob < ActiveFedoraIdBasedJob
43
46
  end
44
47
 
45
48
  f.rewind
46
- return uri.path, mime_type
49
+ [uri.path, mime_type]
47
50
  end
48
51
 
49
52
  def job_user
@@ -12,7 +12,7 @@ class IngestLocalFileJob
12
12
  self.user_key = user_key
13
13
  end
14
14
 
15
- #TODO this should use Actor#create_content
15
+ # TODO: this should use Actor#create_content
16
16
  def run
17
17
  user = User.find_by_user_key(user_key)
18
18
  raise "Unable to find user for #{user_key}" unless user
data/app/models/batch.rb CHANGED
@@ -10,27 +10,21 @@ class Batch < ActiveFedora::Base
10
10
  property :status, predicate: ::RDF::DC.type
11
11
 
12
12
  def self.find_or_create(id)
13
- begin
14
- Batch.find(id)
15
- rescue ActiveFedora::ObjectNotFoundError
16
- safe_create(id)
17
- end
13
+ Batch.find(id)
14
+ rescue ActiveFedora::ObjectNotFoundError
15
+ safe_create(id)
18
16
  end
19
17
 
20
- private
21
-
22
- # This method handles most race conditions gracefully.
23
- # If a batch with the same ID is created by another thread
24
- # we fetch the batch that was created (rather than throwing
25
- # an error) and continute.
26
- def self.safe_create(id)
27
- begin
28
- Batch.create(id: id)
29
- rescue ActiveFedora::IllegalOperation
30
- # This is the exception thrown by LDP when we attempt to
31
- # create a duplicate object. If we can find the object
32
- # then we are good to go.
33
- Batch.find(id)
34
- end
35
- end
18
+ # This method handles most race conditions gracefully.
19
+ # If a batch with the same ID is created by another thread
20
+ # we fetch the batch that was created (rather than throwing
21
+ # an error) and continute.
22
+ def self.safe_create(id)
23
+ Batch.create(id: id)
24
+ rescue ActiveFedora::IllegalOperation
25
+ # This is the exception thrown by LDP when we attempt to
26
+ # create a duplicate object. If we can find the object
27
+ # then we are good to go.
28
+ Batch.find(id)
29
+ end
36
30
  end
@@ -1,5 +1,4 @@
1
1
  class ChecksumAuditLog < ActiveRecord::Base
2
-
3
2
  def self.get_audit_log(id, path, version_uri)
4
3
  ChecksumAuditLog.find_or_create_by(generic_file_id: id, dsid: path, version: version_uri)
5
4
  end
@@ -12,6 +12,7 @@ module Sufia
12
12
  featured_work_abilities
13
13
  editor_abilities
14
14
  stats_abilities
15
+ citation_abilities
15
16
  proxy_deposit_abilities
16
17
  end
17
18
 
@@ -51,6 +52,10 @@ module Sufia
51
52
  alias_action :stats, to: :read
52
53
  end
53
54
 
55
+ def citation_abilities
56
+ alias_action :citation, to: :read
57
+ end
58
+
54
59
  private
55
60
 
56
61
  def depositor_for_document(document_id)
@@ -16,7 +16,7 @@ module Sufia
16
16
  end
17
17
 
18
18
  # Compute the sum of each file in the collection using Solr to
19
- # avoid having to hit Fedora
19
+ # avoid having to hit Fedora
20
20
  #
21
21
  # @return [Fixnum] size of collection in bytes
22
22
  # @raise [RuntimeError] unsaved record does not exist in solr
@@ -34,10 +34,11 @@ module Sufia
34
34
  }
35
35
 
36
36
  files = ActiveFedora::SolrService.query(query, args)
37
- files.reduce(0) { |sum, f| sum += f[file_size_field].to_i }
37
+ files.reduce(0) { |sum, f| sum + f[file_size_field].to_i }
38
38
  end
39
39
 
40
40
  protected
41
+
41
42
  # Field to look up when locating the size of each file in Solr.
42
43
  # Override for your own installation if using something different
43
44
  def file_size_field
@@ -1,35 +1,33 @@
1
1
  module Sufia
2
2
  module FileStatUtils
3
-
4
- def to_flots stats
5
- stats.map {|stat| stat.to_flot}
3
+ def to_flots(stats)
4
+ stats.map(&:to_flot)
6
5
  end
7
6
 
8
- def convert_date date_time
7
+ def convert_date(date_time)
9
8
  date_time.to_datetime.to_i * 1000
10
9
  end
11
10
 
12
11
  private
13
12
 
14
- def cached_stats(file_id, start_date, method)
15
- stats = self.where(file_id:file_id).order(date: :asc)
16
- ga_start_date = stats.size > 0 ? stats[stats.size-1].date + 1.day : start_date.to_date
17
- {ga_start_date: ga_start_date, cached_stats: stats.to_a }
18
- end
13
+ def cached_stats(file_id, start_date, _method)
14
+ stats = where(file_id: file_id).order(date: :asc)
15
+ ga_start_date = stats.size > 0 ? stats[stats.size - 1].date + 1.day : start_date.to_date
16
+ { ga_start_date: ga_start_date, cached_stats: stats.to_a }
17
+ end
19
18
 
20
- def combined_stats file_id, start_date, object_method, ga_key, user_id=nil
21
- stat_cache_info = cached_stats( file_id, start_date, object_method)
22
- stats = stat_cache_info[:cached_stats]
23
- if stat_cache_info[:ga_start_date] < Date.today
24
- ga_stats = ga_statistics(stat_cache_info[:ga_start_date], file_id)
25
- ga_stats.each do |stat|
26
- lstat = self.new file_id: file_id, date: stat[:date], object_method => stat[ga_key], user_id: user_id
27
- lstat.save unless Date.parse(stat[:date]) == Date.today
28
- stats << lstat
19
+ def combined_stats(file_id, start_date, object_method, ga_key, user_id = nil)
20
+ stat_cache_info = cached_stats(file_id, start_date, object_method)
21
+ stats = stat_cache_info[:cached_stats]
22
+ if stat_cache_info[:ga_start_date] < Date.today
23
+ ga_stats = ga_statistics(stat_cache_info[:ga_start_date], file_id)
24
+ ga_stats.each do |stat|
25
+ lstat = new file_id: file_id, date: stat[:date], object_method => stat[ga_key], user_id: user_id
26
+ lstat.save unless Date.parse(stat[:date]) == Date.today
27
+ stats << lstat
28
+ end
29
29
  end
30
+ stats
30
31
  end
31
- stats
32
- end
33
-
34
32
  end
35
33
  end
@@ -19,10 +19,8 @@ module Sufia
19
19
 
20
20
  # Is this file in the middle of being processed by a batch?
21
21
  def processing?
22
- try(:batch).try(:status) == ['processing'.freeze]
22
+ try(:batch).try(:status) == ['processing'.freeze]
23
23
  end
24
-
25
24
  end
26
25
  end
27
26
  end
28
-
@@ -50,7 +50,6 @@ module Sufia
50
50
  property :data_format, delegate_to: 'characterization'
51
51
  property :offset, delegate_to: 'characterization'
52
52
  property :frame_rate, delegate_to: 'characterization'
53
-
54
53
  end
55
54
 
56
55
  def width
@@ -80,19 +79,16 @@ module Sufia
80
79
 
81
80
  # Populate GenericFile's properties with fields from FITS (e.g. Author from pdfs)
82
81
  def append_metadata
83
- terms = self.characterization_terms
82
+ terms = characterization_terms
84
83
  Sufia.config.fits_to_desc_mapping.each_pair do |k, v|
85
- if terms.has_key?(k)
86
- # coerce to array to remove a conditional
87
- terms[k] = [terms[k]] unless terms[k].is_a? Array
88
- terms[k].each do |term_value|
89
- proxy_term = self.send(v)
90
- if proxy_term.kind_of?(Array)
91
- proxy_term << term_value unless proxy_term.include?(term_value)
92
- else
93
- # these are single-valued terms which cannot be appended to
94
- self.send("#{v}=", term_value)
95
- end
84
+ next unless terms.key?(k)
85
+ Array.wrap(terms[k]).each do |term_value|
86
+ proxy_term = send(v)
87
+ if proxy_term.is_a?(Array)
88
+ proxy_term << term_value unless proxy_term.include?(term_value)
89
+ else
90
+ # these are single-valued terms which cannot be appended to
91
+ send("#{v}=", term_value)
96
92
  end
97
93
  end
98
94
  end
@@ -100,11 +96,11 @@ module Sufia
100
96
 
101
97
  def characterization_terms
102
98
  h = {}
103
- FitsDatastream.terminology.terms.each_pair do |k, v|
99
+ FitsDatastream.terminology.terms.each_pair do |_k, v|
104
100
  next unless v.respond_to? :proxied_term
105
101
  term = v.proxied_term
106
102
  begin
107
- value = self.send(term.name)
103
+ value = send(term.name)
108
104
  h[term.name] = value unless value.empty?
109
105
  rescue NoMethodError
110
106
  next
@@ -112,7 +108,6 @@ module Sufia
112
108
  end
113
109
  h
114
110
  end
115
-
116
111
  end
117
112
  end
118
113
  end
@@ -7,7 +7,6 @@ module Sufia
7
7
  contains "content", class_name: 'FileContentDatastream'
8
8
  contains "thumbnail"
9
9
  end
10
-
11
10
  end
12
11
  end
13
12
  end
@@ -9,7 +9,7 @@ module Sufia
9
9
  makes_derivatives do |obj|
10
10
  case obj.mime_type
11
11
  when *pdf_mime_types
12
- obj.transform_file :content, { thumbnail: { format: 'jpg', size: '338x493', datastream: 'thumbnail' } }
12
+ obj.transform_file :content, thumbnail: { format: 'jpg', size: '338x493', datastream: 'thumbnail' }
13
13
  when *office_document_mime_types
14
14
  obj.transform_file :content, { thumbnail: { format: 'jpg', size: '200x150>', datastream: 'thumbnail' } }, processor: :document
15
15
  when *audio_mime_types
@@ -17,7 +17,7 @@ module Sufia
17
17
  when *video_mime_types
18
18
  obj.transform_file :content, { webm: { format: 'webm', datastream: 'webm' }, mp4: { format: 'mp4', datastream: 'mp4' }, thumbnail: { format: 'jpg', datastream: 'thumbnail' } }, processor: :video
19
19
  when *image_mime_types
20
- obj.transform_file :content, { thumbnail: { format: 'jpg', size: '200x150>', datastream: 'thumbnail' } }
20
+ obj.transform_file :content, thumbnail: { format: 'jpg', size: '200x150>', datastream: 'thumbnail' }
21
21
  end
22
22
  end
23
23
  end
@@ -4,8 +4,8 @@ module Sufia
4
4
  # MIME: 'application/x-endnote-refer'
5
5
  def export_as_endnote
6
6
  end_note_format = {
7
- '%T' => [:title, lambda { |x| x.first }],
8
- '%Q' => [:title, lambda { |x| x.drop(1) }],
7
+ '%T' => [:title, ->(x) { x.first }],
8
+ '%Q' => [:title, ->(x) { x.drop(1) }],
9
9
  '%A' => [:creator],
10
10
  '%C' => [:publication_place],
11
11
  '%D' => [:date_created],
@@ -30,15 +30,15 @@ module Sufia
30
30
  if mapping.is_a? String
31
31
  values = [mapping]
32
32
  else
33
- values = self.send(mapping[0]) if self.respond_to? mapping[0]
33
+ values = send(mapping[0]) if self.respond_to? mapping[0]
34
34
  values = mapping[1].call(values) if mapping.length == 2
35
35
  values = Array(values)
36
36
  end
37
- next if values.empty? or values.first.nil?
37
+ next if values.empty? || values.first.nil?
38
38
  spaced_values = values.join("; ")
39
39
  text << "#{endnote_key} #{spaced_values}"
40
40
  end
41
- return text.join("\n")
41
+ text.join("\n")
42
42
  end
43
43
 
44
44
  def persistent_url
@@ -65,10 +65,10 @@ module Sufia
65
65
  rights: 'rights'
66
66
  }
67
67
  field_map.each do |element, kev|
68
- values = self.send(element)
69
- next if values.empty? or values.first.nil?
68
+ values = send(element)
69
+ next if values.empty? || values.first.nil?
70
70
  values.each do |value|
71
- export_text << "rft.#{kev}=#{CGI::escape(value.to_s)}"
71
+ export_text << "rft.#{kev}=#{CGI.escape(value.to_s)}"
72
72
  end
73
73
  end
74
74
  export_text.join('&') unless export_text.blank?
@@ -79,24 +79,24 @@ module Sufia
79
79
  authors_list = []
80
80
  authors_list_final = []
81
81
 
82
- #setup formatted author list
83
- authors = get_author_list
82
+ # setup formatted author list
83
+ authors = author_list
84
84
  authors.each do |author|
85
85
  next if author.blank?
86
86
  authors_list.push(abbreviate_name(author))
87
87
  end
88
88
  authors_list.each do |author|
89
- if author == authors_list.first #first
89
+ if author == authors_list.first # first
90
90
  authors_list_final.push(author.strip)
91
- elsif author == authors_list.last #last
91
+ elsif author == authors_list.last # last
92
92
  authors_list_final.push(", &amp; " + author.strip)
93
- else #all others
93
+ else # all others
94
94
  authors_list_final.push(", " + author.strip)
95
95
  end
96
96
  end
97
97
  text << authors_list_final.join
98
98
  unless text.blank?
99
- if text[-1,1] != "."
99
+ if text[-1, 1] != "."
100
100
  text << ". "
101
101
  else
102
102
  text << " "
@@ -111,11 +111,7 @@ module Sufia
111
111
 
112
112
  # Publisher info
113
113
  text << setup_pub_info unless setup_pub_info.nil?
114
- unless text.blank?
115
- if text[-1,1] != "."
116
- text += "."
117
- end
118
- end
114
+ text += "." if text[-1, 1] != "." unless text.blank?
119
115
  text.html_safe
120
116
  end
121
117
 
@@ -123,22 +119,22 @@ module Sufia
123
119
  text = ''
124
120
  authors_final = []
125
121
 
126
- #setup formatted author list
127
- authors = get_author_list
122
+ # setup formatted author list
123
+ authors = author_list
128
124
 
129
125
  if authors.length < 4
130
126
  authors.each do |author|
131
- if author == authors.first #first
127
+ if author == authors.first # first
132
128
  authors_final.push(author)
133
- elsif author == authors.last #last
129
+ elsif author == authors.last # last
134
130
  authors_final.push(", and " + name_reverse(author) + ".")
135
- else #all others
131
+ else # all others
136
132
  authors_final.push(", " + name_reverse(author))
137
133
  end
138
134
  end
139
135
  text << authors_final.join
140
136
  unless text.blank?
141
- if text[-1,1] != "."
137
+ if text[-1, 1] != "."
142
138
  text << ". "
143
139
  else
144
140
  text << " "
@@ -156,15 +152,13 @@ module Sufia
156
152
 
157
153
  # Get Pub Date
158
154
  text << setup_pub_date unless setup_pub_date.nil?
159
- if text[-1,1] != "."
160
- text << "." unless text.blank?
161
- end
155
+ text << "." unless text.blank? if text[-1, 1] != "."
162
156
  text.html_safe
163
157
  end
164
158
 
165
159
  def export_as_chicago_citation
166
160
  author_text = ""
167
- authors = get_all_authors
161
+ authors = all_authors
168
162
  unless authors.blank?
169
163
  if authors.length > 10
170
164
  authors.each_with_index do |author, index|
@@ -183,7 +177,7 @@ module Sufia
183
177
  end
184
178
  author_text << " et al."
185
179
  elsif authors.length > 1
186
- authors.each_with_index do |author,index|
180
+ authors.each_with_index do |author, index|
187
181
  if index == 0
188
182
  author_text << "#{author}"
189
183
  if author.ends_with?(",")
@@ -202,24 +196,22 @@ module Sufia
202
196
  end
203
197
  end
204
198
  title_info = ""
205
- title_info << citation_title(clean_end_punctuation(CGI::escapeHTML(title.first)).strip) unless title.blank?
199
+ title_info << citation_title(clean_end_punctuation(CGI.escapeHTML(title.first)).strip) unless title.blank?
206
200
 
207
201
  pub_info = ""
208
- place = self.based_near.first
202
+ place = based_near.first
209
203
  publisher = self.publisher.first
210
204
  unless place.blank?
211
- place = CGI::escapeHTML(place)
205
+ place = CGI.escapeHTML(place)
212
206
  pub_info << place
213
207
  pub_info << ": " unless publisher.blank?
214
208
  end
215
209
  unless publisher.blank?
216
- publisher = CGI::escapeHTML(publisher)
210
+ publisher = CGI.escapeHTML(publisher)
217
211
  pub_info << publisher
218
212
  pub_info << ", " unless setup_pub_date.nil?
219
213
  end
220
- unless setup_pub_date.nil?
221
- pub_info << setup_pub_date
222
- end
214
+ pub_info << setup_pub_date unless setup_pub_date.nil?
223
215
 
224
216
  citation = ""
225
217
  citation << "#{author_text} " unless author_text.blank?
@@ -231,10 +223,10 @@ module Sufia
231
223
  private
232
224
 
233
225
  def setup_pub_date
234
- first_date = self.date_created.first
226
+ first_date = date_created.first
235
227
  unless first_date.blank?
236
- first_date = CGI::escapeHTML(first_date)
237
- date_value = first_date.gsub(/[^0-9|n\.d\.]/, "")[0,4]
228
+ first_date = CGI.escapeHTML(first_date)
229
+ date_value = first_date.gsub(/[^0-9|n\.d\.]/, "")[0, 4]
238
230
  return nil if date_value.nil?
239
231
  end
240
232
  clean_end_punctuation(date_value) if date_value
@@ -242,15 +234,15 @@ module Sufia
242
234
 
243
235
  def setup_pub_info
244
236
  text = ''
245
- place = self.based_near.first
237
+ place = based_near.first
246
238
  publisher = self.publisher.first
247
239
  unless place.blank?
248
- place = CGI::escapeHTML(place)
240
+ place = CGI.escapeHTML(place)
249
241
  text << place
250
242
  text << ": " unless publisher.blank?
251
243
  end
252
244
  unless publisher.blank?
253
- publisher = CGI::escapeHTML(publisher)
245
+ publisher = CGI.escapeHTML(publisher)
254
246
  text << publisher
255
247
  end
256
248
  return nil if text.strip.blank?
@@ -258,7 +250,7 @@ module Sufia
258
250
  end
259
251
 
260
252
  def mla_citation_title(text)
261
- no_upcase = ["a","an","and","but","by","for","it","of","the","to","with"]
253
+ no_upcase = ["a", "an", "and", "but", "by", "for", "it", "of", "the", "to", "with"]
262
254
  new_text = []
263
255
  word_parts = text.split(" ")
264
256
  word_parts.each do |w|
@@ -272,12 +264,12 @@ module Sufia
272
264
  end
273
265
 
274
266
  def citation_title(title_text)
275
- prepositions = ["a","about","across","an","and","before","but","by","for","it","of","the","to","with","without"]
267
+ prepositions = ["a", "about", "across", "an", "and", "before", "but", "by", "for", "it", "of", "the", "to", "with", "without"]
276
268
  new_text = []
277
- title_text.split(" ").each_with_index do |word,index|
278
- if (index == 0 and word != word.upcase) or (word.length > 1 and word != word.upcase and !prepositions.include?(word))
269
+ title_text.split(" ").each_with_index do |word, index|
270
+ if (index == 0 && word != word.upcase) || (word.length > 1 && word != word.upcase && !prepositions.include?(word))
279
271
  # the split("-") will handle the capitalization of hyphenated words
280
- new_text << word.split("-").map!{|w| w.capitalize }.join("-")
272
+ new_text << word.split("-").map!(&:capitalize).join("-")
281
273
  else
282
274
  new_text << word
283
275
  end
@@ -289,7 +281,7 @@ module Sufia
289
281
  text = ''
290
282
  title = self.title.first
291
283
  unless title.blank?
292
- title = CGI::escapeHTML(title)
284
+ title = CGI.escapeHTML(title)
293
285
  title_info = clean_end_punctuation(title.strip)
294
286
  text << title_info
295
287
  end
@@ -299,26 +291,26 @@ module Sufia
299
291
  end
300
292
 
301
293
  def clean_end_punctuation(text)
302
- if [".",",",":",";","/"].include? text[-1,1]
303
- return text[0,text.length-1]
294
+ if [".", ",", ":", ";", "/"].include? text[-1, 1]
295
+ return text[0, text.length - 1]
304
296
  end
305
297
  text
306
298
  end
307
299
 
308
- def get_author_list
309
- self.creator.map { |author| clean_end_punctuation(CGI::escapeHTML(author)) }.uniq
300
+ def author_list
301
+ creator.map { |author| clean_end_punctuation(CGI.escapeHTML(author)) }.uniq
310
302
  end
311
303
 
312
- def get_all_authors
313
- authors = self.creator
314
- return authors.empty? ? nil : authors.map { |author| CGI::escapeHTML(author) }
304
+ def all_authors
305
+ authors = creator
306
+ authors.empty? ? nil : authors.map { |author| CGI.escapeHTML(author) }
315
307
  end
316
308
 
317
309
  def abbreviate_name(name)
318
310
  abbreviated_name = ''
319
311
  name = name.join('') if name.is_a? Array
320
312
  # make sure we handle "Cher" correctly
321
- return name if !name.include?(' ') and !name.include?(',')
313
+ return name if !name.include?(' ') && !name.include?(',')
322
314
  surnames_first = name.include?(',')
323
315
  delimiter = surnames_first ? ', ' : ' '
324
316
  name_segments = name.split(delimiter)
@@ -335,9 +327,8 @@ module Sufia
335
327
  name = clean_end_punctuation(name)
336
328
  return name unless name =~ /,/
337
329
  temp_name = name.split(", ")
338
- return temp_name.last + " " + temp_name.first
330
+ temp_name.last + " " + temp_name.first
339
331
  end
340
-
341
332
  end
342
333
  end
343
334
  end