Class: ArchiveOrgLinkGrabber

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/extract_urls.rb

Overview

Defined Under Namespace

Classes: Links

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(urls) ⇒ ArchiveOrgLinkGrabber

Returns a new instance of ArchiveOrgLinkGrabber.



52
53
54
# File 'lib/utils/extract_urls.rb', line 52

def initialize(urls)
  process_urls(Array(urls))
end

Instance Attribute Details

Returns the value of attribute links.



50
51
52
# File 'lib/utils/extract_urls.rb', line 50

def links
  @links
end

Instance Method Details



65
66
67
68
69
70
71
72
# File 'lib/utils/extract_urls.rb', line 65

def extract_links(doc)
  found_links = []
  doc.css('a.stealth.download-pill').each do |link|
    next unless link['href'] =~ /mp3$/
    found_links << link['href']
  end
  found_links
end

#process_urls(urls) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/utils/extract_urls.rb', line 56

def process_urls(urls)
  lnks = []
  urls.each do |url|
    doc = Nokogiri::HTML(open(url))
    lnks = lnks + extract_links(doc)
  end
  self.links = Links.new(lnks)
end

#yaml_formattedObject



74
75
76
# File 'lib/utils/extract_urls.rb', line 74

def yaml_formatted
  links.yaml_formatted
end