Class: Nehm::Track
- Inherits:
-
Object
- Object
- Nehm::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
Used in Get#dl and in Track#file_name.
- #streamable? ⇒ Boolean
- #title ⇒ Object
- #url ⇒ Object
- #year ⇒ Object
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
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
3 4 5 |
# File 'lib/nehm/track.rb', line 3 def hash @hash end |
Instance Method Details
#artist ⇒ Object
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 |
#file_name ⇒ Object
23 24 25 |
# File 'lib/nehm/track.rb', line 23 def file_name "#{name.gsub(/[^0-9A-Za-z -]/, '')}.mp3" end |
#file_path ⇒ Object
27 28 29 |
# File 'lib/nehm/track.rb', line 27 def file_path File.join(PathManager.dl_path, file_name) end |
#id ⇒ Object
31 32 33 |
# File 'lib/nehm/track.rb', line 31 def id @hash['id'] end |
#name ⇒ Object
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
40 41 42 |
# File 'lib/nehm/track.rb', line 40 def streamable? @hash['streamable'] end |
#title ⇒ Object
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 |
#url ⇒ Object
54 55 56 |
# File 'lib/nehm/track.rb', line 54 def url "#{@hash['stream_url']}?client_id=#{Client::CLIENT_ID}" end |
#year ⇒ Object
58 59 60 |
# File 'lib/nehm/track.rb', line 58 def year @hash['created_at'][0..3].to_i end |