Class: Nehm::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.



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

def initialize(hash)
  @hash = hash
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



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

def hash
  @hash
end

Instance Method Details

#artistObject



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

def artist
  title = @hash['title']

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

#artworkObject



19
20
21
# File 'lib/nehm/track.rb', line 19

def artwork
  Artwork.new(self)
end

#file_nameObject



23
24
25
# File 'lib/nehm/track.rb', line 23

def file_name
  "#{name.gsub(/[^0-9A-Za-z -]/, '')}.mp3"
end

#file_pathObject



27
28
29
# File 'lib/nehm/track.rb', line 27

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

#idObject



31
32
33
# File 'lib/nehm/track.rb', line 31

def id
  @hash['id']
end

#nameObject

Used in Get#dl and in Track#file_name



36
37
38
# File 'lib/nehm/track.rb', line 36

def name
  artist + ' - ' + title
end

#streamable?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/nehm/track.rb', line 40

def streamable?
  @hash['streamable']
end

#titleObject



44
45
46
47
48
49
50
51
52
# File 'lib/nehm/track.rb', line 44

def title
  title = @hash['title']

  if title.include? ' - '
    title.split(' - ')[1]
  else
    title
  end
end

#urlObject



54
55
56
# File 'lib/nehm/track.rb', line 54

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

#yearObject



58
59
60
# File 'lib/nehm/track.rb', line 58

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