Class: VkMusic::Audio
- Inherits:
-
Object
- Object
- VkMusic::Audio
- Defined in:
- lib/vk_music/audio.rb
Instance Attribute Summary collapse
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#owner_id ⇒ Object
readonly
Returns the value of attribute owner_id.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#url_encoded ⇒ Object
readonly
Returns the value of attribute url_encoded.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Audio
constructor
A new instance of Audio.
- #to_s ⇒ Object
Constructor Details
#initialize(options) ⇒ Audio
Returns a new instance of Audio.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vk_music/audio.rb', line 13 def initialize() # Arguments check raise ArgumentError, "options hash must be provided", caller unless .class == Hash raise ArgumentError, "artist is not provided", caller unless .has_key?(:artist) raise ArgumentError, "title is not provided", caller unless .has_key?(:title) raise ArgumentError, "duration is not provided", caller unless .has_key?(:duration) # Setting up attributes @id = [:id].to_s @owner_id = [:owner_id].to_s @artist = [:artist].to_s @title = [:title].to_s @duration = [:duration].to_i @url_encoded = [:url_encoded].to_s @url = [:url].to_s end |
Instance Attribute Details
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
7 8 9 |
# File 'lib/vk_music/audio.rb', line 7 def artist @artist end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
7 8 9 |
# File 'lib/vk_music/audio.rb', line 7 def duration @duration end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/vk_music/audio.rb', line 7 def id @id end |
#owner_id ⇒ Object (readonly)
Returns the value of attribute owner_id.
7 8 9 |
# File 'lib/vk_music/audio.rb', line 7 def owner_id @owner_id end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/vk_music/audio.rb', line 7 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/vk_music/audio.rb', line 7 def url @url end |
#url_encoded ⇒ Object (readonly)
Returns the value of attribute url_encoded.
7 8 9 |
# File 'lib/vk_music/audio.rb', line 7 def url_encoded @url_encoded end |
Class Method Details
.from_data_array(data, client_id) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vk_music/audio.rb', line 46 def self.from_data_array(data, client_id) url_encoded = data[2] url_encoded = nil if url_encoded == "" new({ :id => data[0], :owner_id => data[1], :artist => CGI.unescapeHTML(data[4]), :title => CGI.unescapeHTML(data[3]), :duration => data[5], :url_encoded => url_encoded, :url => url_encoded ? VkMusic.unmask_link(url_encoded, client_id) : nil, }) end |
.from_node(node, client_id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vk_music/audio.rb', line 30 def self.from_node(node, client_id) url_encoded = node.at_css("input").attribute("value").to_s url_encoded = nil if url_encoded == "https://m.vk.com/mp3/audio_api_unavailable.mp3" id_array = node.attribute("data-id").to_s.split("_") new({ :id => id_array[1], :owner_id => id_array[0], :artist => node.at_css(".ai_artist").text.strip, :title => node.at_css(".ai_title").text.strip, :duration => node.at_css(".ai_dur").attribute("data-dur").to_s.to_i, :url_encoded => url_encoded, :url => url_encoded ? VkMusic.unmask_link(url_encoded, client_id) : nil, }) end |
Instance Method Details
#to_s ⇒ Object
9 10 11 |
# File 'lib/vk_music/audio.rb', line 9 def to_s "#{@artist} - #{@title} [#{Utility.format_seconds(@duration)}]" end |