Class: PrintLinks

Inherits:
Object
  • Object
show all
Defined in:
lib/print-links.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePrintLinks

Returns a new instance of PrintLinks.



7
8
9
# File 'lib/print-links.rb', line 7

def initialize()
  @links = []
end

Instance Attribute Details

Returns the value of attribute links.



5
6
7
# File 'lib/print-links.rb', line 5

def links
  @links
end

Instance Method Details

#parse_url(url) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/print-links.rb', line 11

def parse_url(url)
  content = open(url).read
  doc = Hpricot(content)
  doc.search("//a").each do |link|
    @links << link.attributes["href"]
  end
  @links
end


20
21
22
23
24
25
26
27
# File 'lib/print-links.rb', line 20

def print(format = :array)
  case format
  when :array
    puts @links.inspect
  when :lines
    @links.each{|link| puts link}
  end
end