Class: MusicBox::Catalog::AlbumTrack

Inherits:
Object
  • Object
show all
Defined in:
lib/musicbox/catalog/album_track.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ AlbumTrack

Returns a new instance of AlbumTrack.



15
16
17
# File 'lib/musicbox/catalog/album_track.rb', line 15

def initialize(params={})
  params.each { |k, v| send("#{k}=", v) }
end

Instance Attribute Details

#albumObject

Returns the value of attribute album.



11
12
13
# File 'lib/musicbox/catalog/album_track.rb', line 11

def album
  @album
end

#artistObject

Returns the value of attribute artist.



8
9
10
# File 'lib/musicbox/catalog/album_track.rb', line 8

def artist
  @artist
end

#discObject

Returns the value of attribute disc.



10
11
12
# File 'lib/musicbox/catalog/album_track.rb', line 10

def disc
  @disc
end

#fileObject

Returns the value of attribute file.



12
13
14
# File 'lib/musicbox/catalog/album_track.rb', line 12

def file
  @file
end

#tagsObject

Returns the value of attribute tags.



13
14
15
# File 'lib/musicbox/catalog/album_track.rb', line 13

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/musicbox/catalog/album_track.rb', line 7

def title
  @title
end

#trackObject

Returns the value of attribute track.



9
10
11
# File 'lib/musicbox/catalog/album_track.rb', line 9

def track
  @track
end

Instance Method Details

#load_tagsObject



27
28
29
# File 'lib/musicbox/catalog/album_track.rb', line 27

def load_tags
  @tags ||= Tags.load(path)
end

#pathObject



23
24
25
# File 'lib/musicbox/catalog/album_track.rb', line 23

def path
  @album.dir / @file
end

#save_tagsObject



31
32
33
# File 'lib/musicbox/catalog/album_track.rb', line 31

def save_tags
  @tags.save(path)
end

#to_hObject



52
53
54
55
56
57
58
59
60
# File 'lib/musicbox/catalog/album_track.rb', line 52

def to_h
  {
    title: @title,
    artist: @artist,
    track: @track,
    disc: @disc,
    file: @file.to_s,
  }.compact
end

#update_tagsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/musicbox/catalog/album_track.rb', line 35

def update_tags
  load_tags
  @tags.update(
    {
      title: @title,
      album: @album.title,
      track: @track,
      disc: @disc,
      discs: @album.discs,
      artist: @artist || @album.artist,
      album_artist: @album.artist,
      grouping: @album.title,
      year: @album.year,
    }.reject { |k, v| v.to_s.empty? }
  )
end