Class: Keenser::Tag
Instance Method Summary
collapse
Methods inherited from Model
each, #find_or_create, schema, without_tables
Instance Method Details
#export! ⇒ Object
20
21
22
23
24
|
# File 'lib/keenser/model/tag.rb', line 20
def export!
File.open playlist, "w" do |f|
songs.each { |s| f.puts s.local_path }
end
end
|
#import(path) ⇒ Object
26
27
28
29
30
31
|
# File 'lib/keenser/model/tag.rb', line 26
def import path
File.read(path).split(/[\r\n]/).each do |line|
next unless line.include? Computer.local.music
end
end
|
#playlist ⇒ Object
16
17
18
|
# File 'lib/keenser/model/tag.rb', line 16
def playlist
"#{Computer.local.playlists}/#{name}.m3u"
end
|
#songs ⇒ Object
12
13
14
|
# File 'lib/keenser/model/tag.rb', line 12
def songs
Song.join(:song_tags, song_id: :id).where(tag_id: id)
end
|
#validate ⇒ Object
7
8
9
10
|
# File 'lib/keenser/model/tag.rb', line 7
def validate
super
errors.add :name, "can't be empty" if name.empty?
end
|