Module: Drakkon::Sounds::Index
- Defined in:
- lib/drakkon/lib/sounds/sounds.rb
Overview
General Sound Index Helper
Class Method Summary collapse
- .build_index ⇒ Object
- .catalog ⇒ Object
-
.check(dir = nil) ⇒ Object
Recursively Go through.
- .context ⇒ Object
- .digest ⇒ Object
- .file_list ⇒ Object
- .index ⇒ Object
- .process(file = nil) ⇒ Object
- .result ⇒ Object
- .run!(force: false, dir: nil) ⇒ Object
- .sounds_directory ⇒ Object
Class Method Details
.build_index ⇒ Object
54 55 56 |
# File 'lib/drakkon/lib/sounds/sounds.rb', line 54 def self.build_index check sounds_directory end |
.catalog ⇒ Object
17 18 19 20 21 22 |
# File 'lib/drakkon/lib/sounds/sounds.rb', line 17 def self.catalog # Better way to do this? @catalog ||= Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) } @catalog end |
.check(dir = nil) ⇒ Object
Recursively Go through
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/drakkon/lib/sounds/sounds.rb', line 76 def self.check(dir = nil) LogBot.info('Sound Index', "Check: #{dir}") # Collect Sounds list = file_list # Ignore Empties return if list.empty? # Do other things Dir["#{dir}/*"].each do |file| if File.directory?(file) check(file) next end process(file) end :done end |
.context ⇒ Object
11 12 13 14 15 |
# File 'lib/drakkon/lib/sounds/sounds.rb', line 11 def self.context @context ||= Dir.pwd @context end |
.digest ⇒ Object
28 29 30 |
# File 'lib/drakkon/lib/sounds/sounds.rb', line 28 def self.digest Digest::MD5.hexdigest(file_list.map { |x| Digest::MD5.file(x).hexdigest }.join) end |
.file_list ⇒ Object
24 25 26 |
# File 'lib/drakkon/lib/sounds/sounds.rb', line 24 def self.file_list Dir["#{sounds_directory}/**/*"].select { |file| File.file?(file) } end |
.index ⇒ Object
5 6 7 8 9 |
# File 'lib/drakkon/lib/sounds/sounds.rb', line 5 def self.index @index ||= {} @index end |
.process(file = nil) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/drakkon/lib/sounds/sounds.rb', line 98 def self.process(file = nil) # Safety return if file.nil? full_name = file.gsub(sounds_directory, '')[1..].gsub(File.extname(file), '') name = File.basename(file, File.extname(file)) path = file.gsub(sounds_directory, '')[1..] index[full_name] = path details = { path: full_name } tag = WahWah.open(file) details[:duration_s] = tag.duration details[:duration_tick] = tag.duration * 60 # Catalog catalog_list = path.split('/')[0..-2] catalog_location = [] catalog_list.each do |idx| catalog_location.push idx catalog.dig(*catalog_location) end catalog.dig(*catalog_list)[name] = details end |
.result ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/drakkon/lib/sounds/sounds.rb', line 58 def self.result <<~RB module Drakkon module Sounds def self.index #{index.inspect} end def self.catalog #{catalog.inspect} end end end RB end |
.run!(force: false, dir: nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/drakkon/lib/sounds/sounds.rb', line 36 def self.run!(force: false, dir: nil) @context = dir || Dir.pwd # Create Directory if sprites directory is missing FileUtils.mkdir_p(sounds_directory) if Settings.config[:sound_digest] == digest && File.exist?("#{context}/app/drakkon/sound_index.rb") LogBot.info('Sounds Index', 'Nothing New') return unless force end build_index Settings.update(:sound_digest, digest) File.write("#{context}/app/drakkon/sound_index.rb", result) end |
.sounds_directory ⇒ Object
32 33 34 |
# File 'lib/drakkon/lib/sounds/sounds.rb', line 32 def self.sounds_directory "#{context}/sounds" end |