Class: Track

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Track

Returns a new instance of Track.



4
5
6
# File 'lib/nehm/track.rb', line 4

def initialize(hash)
  @hash = hash
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



2
3
4
# File 'lib/nehm/track.rb', line 2

def hash
  @hash
end

Instance Method Details

#artistObject



8
9
10
11
12
13
14
15
# File 'lib/nehm/track.rb', line 8

def artist
  if @hash['title'].include?('-')
    title = @hash['title'].split('-')
    title[0].rstrip
  else
    @hash['user']['username']
  end
end

#artworkObject



17
18
19
# File 'lib/nehm/track.rb', line 17

def artwork
  Artwork.new(self)
end

#file_nameObject



21
22
23
# File 'lib/nehm/track.rb', line 21

def file_name
  "#{name}.mp3".tr('/', '')
end

#file_pathObject



25
26
27
# File 'lib/nehm/track.rb', line 25

def file_path
  File.join(PathControl.dl_path, file_name)
end

#idObject



29
30
31
# File 'lib/nehm/track.rb', line 29

def id
  @hash['id'].to_s
end

#nameObject

Use in Get.dl and in Track.file_name



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

def name
  artist + ' - ' + title
end

#titleObject



38
39
40
41
42
43
44
45
# File 'lib/nehm/track.rb', line 38

def title
  if @hash['title'].include?('-')
    title = @hash['title'].split('-')
    title[1].lstrip
  else
    @hash['title']
  end
end

#urlObject



47
48
49
# File 'lib/nehm/track.rb', line 47

def url
  "#{@hash['stream_url']}?client_id=#{Client::CLIENT_ID}"
end

#yearObject



51
52
53
# File 'lib/nehm/track.rb', line 51

def year
  @hash['created_at'][0..3].to_i
end