Module: Worthwhile::SolrDocumentBehavior

Defined in:
app/models/concerns/worthwhile/solr_document_behavior.rb

Instance Method Summary collapse

Instance Method Details

#audio?Boolean

Returns:

  • (Boolean)


136
137
138
139
140
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 136

def audio?
  # audio/x-wave is the mime type that fits 0.6.0 returns for a wav file.
  # audio/mpeg is the mime type that fits 0.6.0 returns for an mp3 file.
  ['audio/mp3', 'audio/mpeg', 'audio/x-wave', 'audio/x-wav', 'audio/ogg'].include? self.mime_type
end

#collection?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 36

def collection?
  hydra_model == 'Collection'
end

#creatorObject



88
89
90
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 88

def creator
  Array(self[Solrizer.solr_name("desc_metadata__creator")]).first
end

#date_uploadedObject



57
58
59
60
61
62
63
64
65
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 57

def date_uploaded
  field = self[Solrizer.solr_name("desc_metadata__date_uploaded", :stored_sortable, type: :date)]
  return unless field.present?
  begin
    Date.parse(field).to_formatted_s(:standard)
  rescue
    Rails.logger.info "Unable to parse date: #{field.first.inspect} for #{self['id']}"
  end
end

#depositor(default = '') ⇒ Object



67
68
69
70
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 67

def depositor(default = '')
  val = Array(self[Solrizer.solr_name("depositor")]).first
  val.present? ? val : default
end

#descriptionObject



76
77
78
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 76

def description
  Array(self[Solrizer.solr_name('desc_metadata__description')]).first
end

#edit_groupsObject



108
109
110
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 108

def edit_groups
  Array(self[::Ability.edit_group_field])
end

#edit_peopleObject



112
113
114
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 112

def edit_people
  Array(self[::Ability.edit_user_field])
end

#file_formatObject



84
85
86
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 84

def file_format
   Array(self[Solrizer.solr_name('file_format')]).first
end

#human_readable_typeObject



49
50
51
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 49

def human_readable_type
  Array(self[Solrizer.solr_name('human_readable_type', :stored_searchable)]).first
end

#hydra_modelObject

Method to return the ActiveFedora model



41
42
43
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 41

def hydra_model
  self[Solrizer.solr_name('active_fedora_model', Solrizer::Descriptor.new(:string, :stored, :indexed))]
end

#image?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 128

def image?
  ['image/png','image/jpeg', 'image/jpg', 'image/jp2', 'image/bmp', 'image/gif', 'image/tiff'].include? self.mime_type
end

#labelObject



80
81
82
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 80

def label
  Array(self[Solrizer.solr_name('label')]).first
end

#mime_typeObject



100
101
102
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 100

def mime_type
  Array(self[Solrizer.solr_name("mime_type")]).first
end

#noidObject



45
46
47
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 45

def noid
  self[Solrizer.solr_name('noid', Sufia::GenericFile.noid_indexer)]
end

#pdf?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 124

def pdf?
  ['application/pdf'].include? self.mime_type
end

#public?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 116

def public?
  read_groups.include?('public')
end

#read_groupsObject



104
105
106
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 104

def read_groups
  Array(self[::Ability.read_group_field])
end

#registered?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 120

def registered?
  read_groups.include?('registered')
end

#representativeObject



53
54
55
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 53

def representative
  Array(self[Solrizer.solr_name('representative', :stored_searchable)]).first
end

#resource_typeObject



96
97
98
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 96

def resource_type
  Array(self[Solrizer.solr_name("desc_metadata__resource_type")])
end

#route_keyObject

Give our SolrDocument an ActiveModel::Naming appropriate route_key



12
13
14
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 12

def route_key
  get(Solrizer.solr_name('has_model', :symbol)).split(':').last.downcase
end

#tagsObject



92
93
94
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 92

def tags
  Array(self[Solrizer.solr_name("desc_metadata__tag")])
end

#titleObject



72
73
74
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 72

def title
  Array(self[Solrizer.solr_name('desc_metadata__title')]).first
end

#title_or_labelObject



6
7
8
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 6

def title_or_label
  title || label
end

#to_modelObject

Offer the source (ActiveFedora-based) model to Rails for some of the Rails methods (e.g. link_to).

Examples:

link_to '...', SolrDocument(:id => 'bXXXXXX5').new => <a href="/dams_object/bXXXXXX5">...</a>


29
30
31
32
33
34
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 29

def to_model
  @model ||= begin
    m = ActiveFedora::Base.load_instance_from_solr(id, self)
    m.class == ActiveFedora::Base ? self : m
  end
end

#to_paramObject



16
17
18
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 16

def to_param
  noid || id
end

#to_sObject



20
21
22
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 20

def to_s
  title_or_label
end

#video?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'app/models/concerns/worthwhile/solr_document_behavior.rb', line 132

def video?
  ['video/mpeg', 'video/mp4', 'video/webm', 'video/x-msvideo', 'video/avi', 'video/quicktime', 'application/mxf'].include? self.mime_type
end