Class: Track
- Inherits:
-
Object
- Object
- Track
- Defined in:
- lib/deadlist/models/track.rb
Instance Attribute Summary collapse
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
-
#available_formats ⇒ Object
Returns formats available for a given track via the links.
-
#has_format?(format) ⇒ Boolean
Returns boolean if a format exists for this Track.
-
#initialize(track_data) ⇒ Track
constructor
A new instance of Track.
-
#url_for_format(format) ⇒ Object
Based on the format argument, returns one link containing that format.
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
#links ⇒ Object (readonly)
Returns the value of attribute links.
2 3 4 |
# File 'lib/deadlist/models/track.rb', line 2 def links @links end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/deadlist/models/track.rb', line 2 def name @name end |
#pos ⇒ Object (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_formats ⇒ Object
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
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 |