Class: Sound
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Sound
- Includes:
- Housekeeping, Shared::Attributions, Shared::Citations, Shared::Confidences, Shared::DataAttributes, Shared::Identifiers, Shared::IsData, Shared::MatrixHooks::Member, Shared::Notes, Shared::Observations, Shared::OriginRelationship, Shared::ProtocolRelationships, Shared::Tags
- Defined in:
- app/models/sound.rb
Overview
A Sound is digital representation of some noise. They are linked ivia Conveyances as Images aer linked via Depictions.
Constant Summary collapse
- ALLOWED_CONTENT_TYPES =
See canonical list at
%w{ audio/wma audio/aac audio/aiff audio/flac audio/mp4 audio/mp3 audio/ogg audio/wav audio/x-wav audio/x-ms-wma audio/x-aiff audio/mpeg }
Class Method Summary collapse
-
.select_optimized(user_id, project_id, target = nil) ⇒ Hash
private
Sounds optimized for user selection.
- .used_recently(user_id, project_id, used_on = '') ⇒ Object private
Instance Method Summary collapse
- #file_type ⇒ Object private
- #purge_sound_file ⇒ Object private
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Shared::Notes
#concatenated_notes_string, #reject_notes
Methods included from Shared::Identifiers
#dwc_occurrence_id, #identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers, #uri, #uuid
Methods included from Shared::DataAttributes
#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes
Methods included from Shared::Attributions
#attributed?, #reject_attribution
Methods included from Shared::Citations
#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id
Methods included from Shared::ProtocolRelationships
#machine_output?, #protocolled?, #reject_protocols
Methods included from Shared::Confidences
Methods included from Shared::OriginRelationship
#new_objects, #old_objects, #reject_origin_relationships, #set_origin
Methods included from Shared::MatrixHooks::Member
#member_add_matrix_columns, #member_add_matrix_rows, #member_add_to_matrix_items, #member_of_new_matrix_column_items, #member_of_new_matrix_row_items, #member_of_old_matrix_column_items, #member_of_old_matrix_row_items, #member_remove_from_matrix_items, #member_remove_matrix_columns, #member_remove_matrix_rows, #member_synchronize_matrices, #member_update_matrix_items?
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Class Method Details
.select_optimized(user_id, project_id, target = nil) ⇒ Hash (private)
Returns sounds optimized for user selection.
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 |
# File 'app/models/sound.rb', line 81 def self.select_optimized(user_id, project_id, target = nil) r = used_recently(user_id, project_id, target) h = { quick: [], pinboard: Sound.pinned_by(user_id).where(project_id:).to_a, recent: [] } if target && !r.empty? h[:recent] = ( Sound.where('"sounds"."id" IN (?)', r.first(5) ).to_a + Sound.where(project_id:, created_by_id: user_id, created_at: 3.hours.ago..Time.now) .order('updated_at DESC') .limit(3).to_a ).uniq.sort{|a,b| a.updated_at <=> b.updated_at} h[:quick] = ( Sound.pinned_by(user_id).pinboard_inserted.where(project_id:).to_a + Sound.where('"sounds"."id" IN (?)', r.first(4) ).to_a) .uniq.sort{|a,b| a.updated_at <=> b.updated_at} else h[:recent] = Sound.where(project_id:).order('updated_at DESC').limit(10).to_a h[:quick] = Sound.pinned_by(user_id).pinboard_inserted.where(pinboard_items: {project_id:}).order('updated_at DESC') end h end |
.used_recently(user_id, project_id, used_on = '') ⇒ Object (private)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/sound.rb', line 59 def self.used_recently(user_id, project_id, used_on = '') i = arel_table d = Conveyance.arel_table # i is a select manager j = d.project(d['sound_id'], d['updated_at'], d['conveyance_object_type']).from(d) .where(d['updated_at'].gt( 1.week.ago )) .where(d['updated_by_id'].eq(user_id)) .where(d['project_id'].eq(project_id)) .order(d['updated_at'].desc) z = j.as('recent_i') k = Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new( z['sound_id'].eq(i['id']).and(z['conveyance_object_type'].eq(used_on)) )) joins(k).distinct.pluck(:id) end |
Instance Method Details
#file_type ⇒ Object (private)
49 50 51 52 53 |
# File 'app/models/sound.rb', line 49 def file_type if !ALLOWED_CONTENT_TYPES.include?(sound_file.content_type) errors.add(:sound_file, "#{sound_file.content_type} is not allowed") end end |
#purge_sound_file ⇒ Object (private)
55 56 57 |
# File 'app/models/sound.rb', line 55 def purge_sound_file sound_file..purge end |