Module: PageParser
- Defined in:
- lib/get_tapas/page_parser.rb
Class Method Summary collapse
-
.parse(html_string) ⇒ Object
An array of DownloadLink instances.
- .ruby_tapas_url_to_filename(url) ⇒ Object
Class Method Details
.parse(html_string) ⇒ Object
Returns an array of DownloadLink instances.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/get_tapas/page_parser.rb', line 17 def self.parse(html_string) html_doc = Nokogiri::HTML(html_string) html_links = html_doc.xpath("//*[contains(@class, 'video-download-link')]") if html_links.empty? raise "No screencast links found. Are you sure about the input HTML source?" else html_links.map do |link| url = link.children.first.attributes['href'].value description = link.children.first.text.strip filename = ruby_tapas_url_to_filename(url) DownloadLink.new(url, filename, description) end end end |
.ruby_tapas_url_to_filename(url) ⇒ Object
Example Input: “rubytapas-media.s3.amazonaws.com/298-file-find.mp4?response-content-disposition=… Example Return: ‘298-file-find.mp4’
10 11 12 |
# File 'lib/get_tapas/page_parser.rb', line 10 def self.ruby_tapas_url_to_filename(url) url.split('?').first.split('/').last end |