Class: PrintLinks
- Inherits:
-
Object
- Object
- PrintLinks
- Defined in:
- lib/print-links.rb
Instance Attribute Summary collapse
-
#links ⇒ Object
Returns the value of attribute links.
Instance Method Summary collapse
-
#initialize ⇒ PrintLinks
constructor
A new instance of PrintLinks.
- #parse_url(url) ⇒ Object
- #print(format = :array) ⇒ Object
Constructor Details
#initialize ⇒ PrintLinks
Returns a new instance of PrintLinks.
7 8 9 |
# File 'lib/print-links.rb', line 7 def initialize() @links = [] end |
Instance Attribute Details
#links ⇒ Object
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 |
#print(format = :array) ⇒ Object
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 |