Class: Snackhack2::WebsiteLinks
- Inherits:
-
Object
- Object
- Snackhack2::WebsiteLinks
- Defined in:
- lib/snackhack2/website_links.rb
Instance Attribute Summary collapse
-
#save_file ⇒ Object
Returns the value of attribute save_file.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
-
#initialize(save_file: true) ⇒ WebsiteLinks
constructor
A new instance of WebsiteLinks.
- #run ⇒ Object
Constructor Details
#initialize(save_file: true) ⇒ WebsiteLinks
Returns a new instance of WebsiteLinks.
9 10 11 12 |
# File 'lib/snackhack2/website_links.rb', line 9 def initialize(save_file: true) @site = site @save_file = save_file end |
Instance Attribute Details
#save_file ⇒ Object
Returns the value of attribute save_file.
7 8 9 |
# File 'lib/snackhack2/website_links.rb', line 7 def save_file @save_file end |
#site ⇒ Object
Returns the value of attribute site.
7 8 9 |
# File 'lib/snackhack2/website_links.rb', line 7 def site @site end |
Instance Method Details
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/snackhack2/website_links.rb', line 14 def run doc = Nokogiri::HTML(URI.open(@site)) links = doc.xpath('//a') all_links = links.map { |e| e['href'] }.compact content = all_links.uniq.join("\n") if @save_file Snackhack2::file_save(@site, "links", content) else all_links.each do |links| puts links end end end |