Class: Track
- Inherits:
-
Object
- Object
- Track
- Defined in:
- lib/nehm/track.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #artist ⇒ Object
- #artwork ⇒ Object
- #file_name ⇒ Object
- #file_path ⇒ Object
- #id ⇒ Object
-
#initialize(hash) ⇒ Track
constructor
A new instance of Track.
-
#name ⇒ Object
Use in Get.dl and in Track.file_name.
- #title ⇒ Object
- #url ⇒ Object
- #year ⇒ Object
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
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
2 3 4 |
# File 'lib/nehm/track.rb', line 2 def hash @hash end |
Instance Method Details
#artist ⇒ Object
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 |
#file_name ⇒ Object
21 22 23 |
# File 'lib/nehm/track.rb', line 21 def file_name "#{name}.mp3".tr('/', '') end |
#file_path ⇒ Object
25 26 27 |
# File 'lib/nehm/track.rb', line 25 def file_path File.join(PathControl.dl_path, file_name) end |
#id ⇒ Object
29 30 31 |
# File 'lib/nehm/track.rb', line 29 def id @hash['id'].to_s end |
#name ⇒ Object
Use in Get.dl and in Track.file_name
34 35 36 |
# File 'lib/nehm/track.rb', line 34 def name artist + ' - ' + title end |
#title ⇒ Object
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 |
#url ⇒ Object
47 48 49 |
# File 'lib/nehm/track.rb', line 47 def url "#{@hash['stream_url']}?client_id=#{Client::CLIENT_ID}" end |
#year ⇒ Object
51 52 53 |
# File 'lib/nehm/track.rb', line 51 def year @hash['created_at'][0..3].to_i end |