Class: Musictree::Track

Inherits:
Object
  • Object
show all
Defined in:
lib/musictree/track.rb

Overview

A track holds the meta information for one music file

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Track

Returns a new instance of Track.



19
20
21
22
23
# File 'lib/musictree/track.rb', line 19

def initialize(path)
  @path = path
  @title = File.basename(@path) # Let's set a preliminary name
  parse_file
end

Instance Attribute Details

#albumObject (readonly)

Returns the value of attribute album.



9
10
11
# File 'lib/musictree/track.rb', line 9

def album
  @album
end

#artistObject (readonly)

Returns the value of attribute artist.



9
10
11
# File 'lib/musictree/track.rb', line 9

def artist
  @artist
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/musictree/track.rb', line 9

def path
  @path
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/musictree/track.rb', line 9

def title
  @title
end

#trackObject (readonly)

Returns the value of attribute track.



9
10
11
# File 'lib/musictree/track.rb', line 9

def track
  @track
end

Class Method Details

.scan(path) ⇒ Object

Scan a music file for metadata (The method name is consistent to the other classes but a bit shit)

Parameters:

  • path (String)

    path to the source music file



13
14
15
16
17
# File 'lib/musictree/track.rb', line 13

def self.scan(path)
  moi = new(path)
  moi.parse_file
  moi
end

Instance Method Details

#inspectObject



25
26
27
28
29
30
31
32
33
# File 'lib/musictree/track.rb', line 25

def inspect
  {
    path: @path,
    title: @title,
    artist: @artist,
    track: @track_no,
    album: @album
  }.inspect
end

#parse_fileObject



35
36
37
38
39
40
41
# File 'lib/musictree/track.rb', line 35

def parse_file
  tag = WahWah.open(@path)
  @title = tag.title
  @artist = tag.artist
  @track = tag.track
  @album = tag.album
end