Class: Vnehm::Track

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

Overview

Primitive for SoundCloud track

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hashObject (readonly)

Returns the value of attribute hash.



7
8
9
# File 'lib/vnehm/track.rb', line 7

def hash
  @hash
end

Instance Method Details

#artistObject



13
14
15
# File 'lib/vnehm/track.rb', line 13

def artist
  CGI::unescapeHTML(@hash.artist)
end

#durationObject



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_nameObject



26
27
28
# File 'lib/vnehm/track.rb', line 26

def file_name
  "#{full_name.tr(",./'\\\"$%", '')}.mp3"
end

#file_pathObject



30
31
32
# File 'lib/vnehm/track.rb', line 30

def file_path
  File.join(ENV['dl_path'], file_name)
end

#full_nameObject



34
35
36
# File 'lib/vnehm/track.rb', line 34

def full_name
  "#{artist} - #{title}"
end

#idObject



38
39
40
# File 'lib/vnehm/track.rb', line 38

def id
  @hash.aid
end

#titleObject



42
43
44
# File 'lib/vnehm/track.rb', line 42

def title
  CGI::unescapeHTML(@hash.title)
end

#urlObject



46
47
48
# File 'lib/vnehm/track.rb', line 46

def url
  @hash.url
end