Module: SoundsHelper

Defined in:
app/helpers/sounds_helper.rb

Instance Method Summary collapse

Instance Method Details

#label_for_sound(sound) ⇒ Object



10
11
12
13
# File 'app/helpers/sounds_helper.rb', line 10

def label_for_sound(sound)
  return nil if sound.nil?
  sound.name || "sound #{sound.id}"
end


19
20
21
22
# File 'app/helpers/sounds_helper.rb', line 19

def sound_link(sound)
  return nil if sound.nil?
  link_to(sound_tag(sound), sound.metamorphosize).html_safe
end

#sound_metadata(sound) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/sounds_helper.rb', line 24

def (sound)
 return {} if sound.nil?
 t = File.open( ActiveStorage::Blob.service.path_for(sound.sound_file.attachment.key))
 w = ::WahWah.open(t)
 # This brakes on binary strings
 #m = w.as_json.compact.delete_if{|k,v| v.blank?}
 #m.delete 'file_io'
 #m

 # Metadata. Add more as needed.
 {
   duration: w.duration,
   sample_rate: w.sample_rate
 }
end

#sound_tag(sound) ⇒ Object



3
4
5
6
7
8
# File 'app/helpers/sounds_helper.rb', line 3

def sound_tag(sound)
  return nil if sound.nil?
  [ sound.name,
    sound.sound_file.attachment.filename.to_s
  ].compact.join(': ')
end

#sounds_search_formObject



15
16
17
# File 'app/helpers/sounds_helper.rb', line 15

def sounds_search_form
  render('/sounds/quick_search_form')
end