Class: MusicBlender::MusicFolder

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/music_blender/music_folder.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.currentObject



5
6
7
# File 'lib/music_blender/music_folder.rb', line 5

def self.current
  @current ||= MusicFolder.find_or_create_by(path: music_path)
end

.music_pathObject



9
10
11
# File 'lib/music_blender/music_folder.rb', line 9

def self.music_path
  MUSIC_PATH
end

Instance Method Details

#load_tracksObject



22
23
24
25
26
27
# File 'lib/music_blender/music_folder.rb', line 22

def load_tracks
  relative_paths.each do |relative_path|
    track = tracks.find_or_create_by(:relative_path => relative_path)
    track.import_id3_tag_attributes!
  end
end

#pick_a_trackObject



13
14
15
16
17
18
19
20
# File 'lib/music_blender/music_folder.rb', line 13

def pick_a_track
  tracks.
    except_missing.
    except_recently_played.
    except_by_recently_played_artists.
    by_weighted_random.
    last
end

#update_missing_flagsObject



29
30
31
32
33
# File 'lib/music_blender/music_folder.rb', line 29

def update_missing_flags
  tracks.each do |track|
    track.update_column(:missing, ! File.exists?(track.full_path))
  end
end