class Nehm::Track
Primitive for SoundCloud track
Attributes
hash[R]
Public Class Methods
new(hash)
click to toggle source
# File lib/nehm/track.rb, line 11 def initialize(hash) @hash = hash end
Public Instance Methods
artist()
click to toggle source
# File lib/nehm/track.rb, line 15 def artist name[0] end
artwork()
click to toggle source
# File lib/nehm/track.rb, line 19 def artwork Artwork.new(self) end
duration()
click to toggle source
# File lib/nehm/track.rb, line 23 def duration seconds = @hash['duration'] / 1000 time = Time.at(seconds) time -= time.utc_offset time.hour > 0 ? time.strftime('%H:%M:%S') : time.strftime('%M:%S') end
file_name()
click to toggle source
# File lib/nehm/track.rb, line 32 def file_name "#{full_name.tr(",./'\\\"$%", '')}.mp3" end
file_path()
click to toggle source
# File lib/nehm/track.rb, line 36 def file_path File.join(ENV['dl_path'], file_name) end
full_name()
click to toggle source
# File lib/nehm/track.rb, line 40 def full_name "#{artist} - #{title}" end
id()
click to toggle source
# File lib/nehm/track.rb, line 44 def id @hash['id'] end
name()
click to toggle source
Returns artist and title in array
# File lib/nehm/track.rb, line 49 def name title = @hash['title'] separators = [' - ', ' ~ '] separators.each do |sep| return title.split(sep, 2) if title.include? sep end [@hash['user']['username'], title] end
title()
click to toggle source
# File lib/nehm/track.rb, line 60 def title name[1] end
url()
click to toggle source
# File lib/nehm/track.rb, line 64 def url # API V2 track hash has no 'stream_url' but 'uri' dl_url = @hash['uri'] ? "#{@hash['uri']}/stream" : @hash['stream_url'] "#{dl_url}?client_id=#{HTTPClient::CLIENT_ID}" end
year()
click to toggle source
# File lib/nehm/track.rb, line 70 def year @hash['created_at'][0..3].to_i end