-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.rb
56 lines (48 loc) · 980 Bytes
/
db.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'song.rb'
class Database
attr_reader :songs
def initialize
@songs = []
@folders = []
@sidhash = {}
end
def addFolder folder
["zip", "cdg", "avi", "flv", "mp4"].each do |type|
Dir.glob("#{folder}/**/*.#{type}").each do |filename|
split = File.split(filename)
song = Song.new(filename, split[1])
@songs.push(song)
@sidhash[song.sid] = song
end
end
@folders << folder if not @folders.include?(folder)
end
def lookup sid
return @sidhash[sid]
end
def sort!
@songs.sort! { |a,b| a.to_s <=> b.to_s }
end
def reload!
@songs.clear
@sidhash.clear
@folders.each do |folder|
addFolder(folder)
end
end
def search term
results = []
words = term.upcase.split(" ")
@songs.each do |song|
match = true
words.each do |word|
if not song.match(word)
match = false
break
end
end
results.push song if match
end
return results
end
end