Class: Playlist::Track
- Inherits:
-
Object
- Object
- Playlist::Track
- Defined in:
- lib/playlist/track.rb
Overview
Data model class that represents a single track.
Instance Attribute Summary collapse
-
#album ⇒ String
The name of the album that the track came from.
-
#catalogue_number ⇒ String
The catalogue number of the album that the track came from Also known as the UPC/EAN code.
-
#contributors ⇒ Array<Contributor>
readonly
Get the array of the contributors to this Track.
-
#description ⇒ String
A description/annotation/synopsis of the track.
-
#duration ⇒ Integer, Float
The duration of the track in milliseconds May be a Float to include fractions of a millisecond.
-
#identifiers ⇒ Hash
readonly
Get a hash of identifier for this Track Identifiers can either be Strings or URIs.
-
#image ⇒ String
URI of an image associated with this Track.
-
#location ⇒ Object
A URI (or filename) to the location of the file.
-
#publisher ⇒ String
The name of the publisher that published the score/lyrics of the song.
-
#record_label ⇒ String
The name of the record label that published the track/album.
-
#side ⇒ String
The side of disc if the track came from a vinyl album (eg A/B).
-
#start_time ⇒ Integer, Float
The time a track starts playing at, in milliseconds May be a Float to include fractions of a millisecond.
-
#title ⇒ String
The title of the track.
-
#track_number ⇒ Integer
The number of the track on the album it came from.
Instance Method Summary collapse
-
#add_contributor(args) ⇒ Object
Add a contributor to the Track.
-
#arranger ⇒ String
Get a conactinated list of arrangers for this track.
-
#arranger=(name) ⇒ Object
Set the name of the arranger for the track Removes any existing arrangers.
-
#composer ⇒ String
Get a conactinated list of composers for this track.
-
#composer=(name) ⇒ Object
Set the name of the composer for the track Removes any existing composers.
-
#contributor_names(role = :any) ⇒ String
Get a concatinated list of contributor names for a specific role.
-
#creator ⇒ String
Get a concatinated list of contributors names with no role.
-
#creator=(name) ⇒ Object
Set the name of the contributor with no role Removes any existing contributors with no role.
-
#initialize(attr = {}) {|_self| ... } ⇒ Track
constructor
Create a new Track.
-
#isrc ⇒ String
Get the International Standard Recording Code for this track.
-
#isrc=(isrc) ⇒ Object
Set the International Standard Recording Code for this track.
-
#performer ⇒ String
(also: #artist)
Get a conactinated list of performers for this track If there are no performers, return contributors with no role.
-
#performer=(name) ⇒ Object
(also: #artist=)
Set the name of the track performer Removes any existing performers.
-
#replace_contributor(role, name) ⇒ Object
First deletes any contribitors with same role, then adds a new contributor.
-
#to_h ⇒ Hash
Get all the attributes of the track object as a Hash.
Constructor Details
#initialize(attr = {}) {|_self| ... } ⇒ Track
Create a new Track
64 65 66 67 68 69 70 71 72 |
# File 'lib/playlist/track.rb', line 64 def initialize(attr = {}) @contributors = [] @identifiers = {} attr.each_pair do |key, value| send("#{key}=", value) end yield(self) if block_given? end |
Instance Attribute Details
#album ⇒ String
The name of the album that the track came from
12 13 14 |
# File 'lib/playlist/track.rb', line 12 def album @album end |
#catalogue_number ⇒ String
The catalogue number of the album that the track came from Also known as the UPC/EAN code
21 22 23 |
# File 'lib/playlist/track.rb', line 21 def catalogue_number @catalogue_number end |
#contributors ⇒ Array<Contributor> (readonly)
Get the array of the contributors to this Track
56 57 58 |
# File 'lib/playlist/track.rb', line 56 def contributors @contributors end |
#description ⇒ String
A description/annotation/synopsis of the track
16 17 18 |
# File 'lib/playlist/track.rb', line 16 def description @description end |
#duration ⇒ Integer, Float
The duration of the track in milliseconds May be a Float to include fractions of a millisecond.
47 48 49 |
# File 'lib/playlist/track.rb', line 47 def duration @duration end |
#identifiers ⇒ Hash (readonly)
Get a hash of identifier for this Track Identifiers can either be Strings or URIs
52 53 54 |
# File 'lib/playlist/track.rb', line 52 def identifiers @identifiers end |
#image ⇒ String
URI of an image associated with this Track
60 61 62 |
# File 'lib/playlist/track.rb', line 60 def image @image end |
#location ⇒ Object
A URI (or filename) to the location of the file
4 5 6 |
# File 'lib/playlist/track.rb', line 4 def location @location end |
#publisher ⇒ String
The name of the publisher that published the score/lyrics of the song
37 38 39 |
# File 'lib/playlist/track.rb', line 37 def publisher @publisher end |
#record_label ⇒ String
The name of the record label that published the track/album
33 34 35 |
# File 'lib/playlist/track.rb', line 33 def record_label @record_label end |
#side ⇒ String
The side of disc if the track came from a vinyl album (eg A/B)
29 30 31 |
# File 'lib/playlist/track.rb', line 29 def side @side end |
#start_time ⇒ Integer, Float
The time a track starts playing at, in milliseconds May be a Float to include fractions of a millisecond.
42 43 44 |
# File 'lib/playlist/track.rb', line 42 def start_time @start_time end |
#title ⇒ String
The title of the track
8 9 10 |
# File 'lib/playlist/track.rb', line 8 def title @title end |
#track_number ⇒ Integer
The number of the track on the album it came from
25 26 27 |
# File 'lib/playlist/track.rb', line 25 def track_number @track_number end |
Instance Method Details
#add_contributor(args) ⇒ Object
Add a contributor to the Track
161 162 163 164 165 166 167 |
# File 'lib/playlist/track.rb', line 161 def add_contributor(args) @contributors << if args.is_a?(Playlist::Contributor) args else Playlist::Contributor.new(args) end end |
#arranger ⇒ String
Get a conactinated list of arrangers for this track
130 131 132 |
# File 'lib/playlist/track.rb', line 130 def arranger contributor_names(:arranger) end |
#arranger=(name) ⇒ Object
Set the name of the arranger for the track Removes any existing arrangers
137 138 139 |
# File 'lib/playlist/track.rb', line 137 def arranger=(name) replace_contributor(:arranger, name) end |
#composer ⇒ String
Get a conactinated list of composers for this track
117 118 119 |
# File 'lib/playlist/track.rb', line 117 def composer contributor_names(:composer) end |
#composer=(name) ⇒ Object
Set the name of the composer for the track Removes any existing composers
124 125 126 |
# File 'lib/playlist/track.rb', line 124 def composer=(name) replace_contributor(:composer, name) end |
#contributor_names(role = :any) ⇒ String
Get a concatinated list of contributor names for a specific role
181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/playlist/track.rb', line 181 def contributor_names(role = :any) filtered = if role == :any @contributors else @contributors.find_all { |c| c.role == role } end if filtered.count == 1 filtered.first.name elsif filtered.count >= 2 filtered[0..-2].map(&:name).join(', ') + ' & ' + filtered.last.name end end |
#creator ⇒ String
Get a concatinated list of contributors names with no role
88 89 90 |
# File 'lib/playlist/track.rb', line 88 def creator contributor_names(nil) end |
#creator=(name) ⇒ Object
Set the name of the contributor with no role Removes any existing contributors with no role
95 96 97 |
# File 'lib/playlist/track.rb', line 95 def creator=(name) replace_contributor(nil, name) end |
#isrc ⇒ String
Get the International Standard Recording Code for this track
76 77 78 |
# File 'lib/playlist/track.rb', line 76 def isrc @identifiers[:isrc] end |
#isrc=(isrc) ⇒ Object
Set the International Standard Recording Code for this track
82 83 84 |
# File 'lib/playlist/track.rb', line 82 def isrc=(isrc) @identifiers[:isrc] = isrc end |
#performer ⇒ String Also known as: artist
Get a conactinated list of performers for this track If there are no performers, return contributors with no role
102 103 104 |
# File 'lib/playlist/track.rb', line 102 def performer contributor_names(:performer) || contributor_names(nil) end |
#performer=(name) ⇒ Object Also known as: artist=
Set the name of the track performer Removes any existing performers
110 111 112 |
# File 'lib/playlist/track.rb', line 110 def performer=(name) replace_contributor(:performer, name) end |
#replace_contributor(role, name) ⇒ Object
First deletes any contribitors with same role, then adds a new contributor
172 173 174 175 |
# File 'lib/playlist/track.rb', line 172 def replace_contributor(role, name) @contributors.delete_if { |c| c.role == role } add_contributor(:role => role, :name => name) end |
#to_h ⇒ Hash
Get all the attributes of the track object as a Hash
197 198 199 200 201 202 203 |
# File 'lib/playlist/track.rb', line 197 def to_h Hash[ instance_variables.map do |v| [v.to_s[1..-1].to_sym, instance_variable_get(v)] end ] end |