Class: PageScrape
- Inherits:
-
Object
- Object
- PageScrape
- Defined in:
- lib/page_scrape.rb
Instance Attribute Summary collapse
-
#search_result ⇒ Object
readonly
Returns the value of attribute search_result.
-
#search_string ⇒ Object
Returns the value of attribute search_string.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(uri, search_string) ⇒ PageScrape
constructor
A new instance of PageScrape.
- #scrape(uri = @uri, search_string = @search_string) ⇒ Object
Constructor Details
#initialize(uri, search_string) ⇒ PageScrape
Returns a new instance of PageScrape.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/page_scrape.rb', line 9 def initialize(uri, search_string) #Returning nil instead of raising works #for this class' intended purpose. #Bad URIs are expected, so we're not #concerned about finding one. begin @uri = URI.parse(uri).read rescue @uri = "" end @search_string = search_string self.scrape end |
Instance Attribute Details
#search_result ⇒ Object (readonly)
Returns the value of attribute search_result.
7 8 9 |
# File 'lib/page_scrape.rb', line 7 def search_result @search_result end |
#search_string ⇒ Object
Returns the value of attribute search_string.
6 7 8 |
# File 'lib/page_scrape.rb', line 6 def search_string @search_string end |
#uri ⇒ Object
Returns the value of attribute uri.
6 7 8 |
# File 'lib/page_scrape.rb', line 6 def uri @uri end |
Instance Method Details
#scrape(uri = @uri, search_string = @search_string) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/page_scrape.rb', line 25 def scrape(uri = @uri, search_string = @search_string) #Set @search_result to nil each time you scrape #otherwise it will always return true, even if you #re-scrape @search_result = nil @search_result = true if uri.match(search_string) end |