Sha256: 1d2a83115f7ad87717c8addcfe5ae7b805952df43e2bc6e51b52aaba73ba90a9

Contents?: true

Size: 1006 Bytes

Versions: 2

Compression:

Stored size: 1006 Bytes

Contents

require 'nokogiri'

require_relative 'download_link'

module PageParser


  # Example Input: "https://rubytapas-media.s3.amazonaws.com/298-file-find.mp4?response-content-disposition=...
  # Example Return: '298-file-find.mp4'
  def self.ruby_tapas_url_to_filename(url)
    url.split('?').first.split('/').last
  end


  # @param html_string an HTML string from https://www.rubytapas.com/download-list/
  # @return an array of DownloadLink instances.
  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
get_tapas-0.9.5 lib/get_tapas/page_parser.rb
get_tapas-0.9.4 lib/get_tapas/page_parser.rb