Class: UrlExtractor::HTML
- Inherits:
-
Object
- Object
- UrlExtractor::HTML
- Defined in:
- lib/url_extractor/html.rb
Constant Summary collapse
- InvalidURL =
Class.new(StandardError)
Instance Method Summary collapse
-
#initialize(ignore_patterns = []) ⇒ HTML
constructor
A new instance of HTML.
- #replace_urls(template) ⇒ Object
Constructor Details
#initialize(ignore_patterns = []) ⇒ HTML
Returns a new instance of HTML.
8 9 10 |
# File 'lib/url_extractor/html.rb', line 8 def initialize(ignore_patterns = []) @ignore_patterns = ignore_patterns end |
Instance Method Details
#replace_urls(template) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/url_extractor/html.rb', line 12 def replace_urls(template) document = Nokogiri::HTML(template) document.search("a").each do |link| url = link['href'] raise InvalidURL, "cannot be blank" if UrlExtractor::Util.blank_string?(url) next if ignored_url?(url) link['href'] = yield(url) end document.to_s end |