Class: VkMusic::WebParser::Search

Inherits:
Base
  • Object
show all
Defined in:
lib/vk_music/web_parser/search.rb

Overview

Audio search page parser

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from VkMusic::WebParser::Base

Instance Method Details

#audiosArray<Audio>

Audios found

Returns:



9
10
11
12
13
14
15
16
# File 'lib/vk_music/web_parser/search.rb', line 9

def audios
  title_index = search_result_blocks.find_index { |node| node.inner_text.include?('Все аудиозаписи') }
  return [] if title_index.nil?

  block = search_result_blocks[title_index + 1]

  Utility::AudioItemsParser.call(block, @client_id)
end

#audios_all_pathString?

Path to page with all results

Returns:

  • (String?)


20
21
22
23
24
25
# File 'lib/vk_music/web_parser/search.rb', line 20

def audios_all_path
  title = search_result_blocks.find { |node| node.inner_text.include?('Все аудиозаписи') }
  return if title.nil?

  title.at_css('a').attribute('href').value
end

#playlistsArray<Playlist>

Playlists found

Returns:



29
30
31
32
33
34
35
36
37
38
# File 'lib/vk_music/web_parser/search.rb', line 29

def playlists
  title_index = search_result_blocks.find_index { |node| node.inner_text.include?('Альбомы') }
  return [] if title_index.nil?

  block = search_result_blocks[title_index + 1]

  block.css('.audioPlaylists__item').map do |elem|
    Utility::PlaylistNodeParser.call(elem)
  end
end

#playlists_all_pathString?

Path to page with all results

Returns:

  • (String?)


42
43
44
45
46
47
# File 'lib/vk_music/web_parser/search.rb', line 42

def playlists_all_path
  title = search_result_blocks.find { |node| node.inner_text.include?('Альбомы') }
  return if title.nil?

  title.at_css('a').attribute('href').value
end