Class: Track

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(track_data) ⇒ Track

Returns a new instance of Track.



4
5
6
7
8
# File 'lib/deadlist/models/track.rb', line 4

def initialize(track_data)
  @pos = track_data[:pos]
  @name = track_data[:name]
  @links = track_data[:links]
end

Instance Attribute Details

Returns the value of attribute links.



2
3
4
# File 'lib/deadlist/models/track.rb', line 2

def links
  @links
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/deadlist/models/track.rb', line 2

def name
  @name
end

#posObject (readonly)

Returns the value of attribute pos.



2
3
4
# File 'lib/deadlist/models/track.rb', line 2

def pos
  @pos
end

Instance Method Details

#available_formatsObject

Returns formats available for a given track via the links



11
12
13
# File 'lib/deadlist/models/track.rb', line 11

def available_formats
  @available_formats ||= links.map { |url| File.extname(url).delete('.') }
end

#has_format?(format) ⇒ Boolean

Returns boolean if a format exists for this Track

Returns:

  • (Boolean)


21
22
23
# File 'lib/deadlist/models/track.rb', line 21

def has_format?(format)
  available_formats.include?(format)
end

#url_for_format(format) ⇒ Object

Based on the format argument, returns one link containing that format



16
17
18
# File 'lib/deadlist/models/track.rb', line 16

def url_for_format(format)
  links.find { |url| url.end_with?(".#{format}") }
end