Class: Vnehm::Track
- Inherits:
-
Object
- Object
- Vnehm::Track
- Defined in:
- lib/vnehm/track.rb
Overview
Primitive for SoundCloud track
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #artist ⇒ Object
- #duration ⇒ Object
- #file_name ⇒ Object
- #file_path ⇒ Object
- #full_name ⇒ Object
- #id ⇒ Object
-
#initialize(hash) ⇒ Track
constructor
A new instance of Track.
- #title ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(hash) ⇒ Track
Returns a new instance of Track.
9 10 11 |
# File 'lib/vnehm/track.rb', line 9 def initialize(hash) @hash = hash end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
7 8 9 |
# File 'lib/vnehm/track.rb', line 7 def hash @hash end |
Instance Method Details
#artist ⇒ Object
13 14 15 |
# File 'lib/vnehm/track.rb', line 13 def artist CGI::unescapeHTML(@hash.artist) end |
#duration ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/vnehm/track.rb', line 17 def duration seconds = @hash['duration'] time = Time.at(seconds) time -= time.utc_offset time.hour > 0 ? time.strftime("%H:%M:%S") : time.strftime("%M:%S") end |
#file_name ⇒ Object
26 27 28 |
# File 'lib/vnehm/track.rb', line 26 def file_name "#{full_name.tr(',./\\\'$%"', '')}.mp3" end |
#file_path ⇒ Object
30 31 32 |
# File 'lib/vnehm/track.rb', line 30 def file_path File.join(ENV['dl_path'], file_name) end |
#full_name ⇒ Object
34 35 36 |
# File 'lib/vnehm/track.rb', line 34 def full_name "#{artist} - #{title}" end |
#id ⇒ Object
38 39 40 |
# File 'lib/vnehm/track.rb', line 38 def id @hash.aid end |
#title ⇒ Object
42 43 44 |
# File 'lib/vnehm/track.rb', line 42 def title CGI::unescapeHTML(@hash.title) end |
#url ⇒ Object
46 47 48 |
# File 'lib/vnehm/track.rb', line 46 def url @hash.url end |