Class: Scrapzirra::Scrap
- Inherits:
-
Object
- Object
- Scrapzirra::Scrap
- Defined in:
- lib/scrapzirra/scrap.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #doc ⇒ Object
-
#initialize(url, options = {}) ⇒ Scrap
constructor
A new instance of Scrap.
- #load_doc ⇒ Object
- #selector_content(css) ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ Scrap
Returns a new instance of Scrap.
5 6 7 8 |
# File 'lib/scrapzirra/scrap.rb', line 5 def initialize url, = {} @url = url @doc = Nokogiri::HTML([:doc]) if [:doc] end |
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/scrapzirra/scrap.rb', line 3 def url @url end |
Instance Method Details
#doc ⇒ Object
10 11 12 |
# File 'lib/scrapzirra/scrap.rb', line 10 def doc @doc || load_doc end |
#load_doc ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/scrapzirra/scrap.rb', line 14 def load_doc require 'nokogiri' require 'open-uri' @doc = Nokogiri::HTML(open(@url).read) @doc.encoding = 'utf-8' @doc rescue @doc = Nokogiri::HTML::Document.parse('No data') end |
#selector_content(css) ⇒ Object
25 26 27 |
# File 'lib/scrapzirra/scrap.rb', line 25 def selector_content css doc.css(css).collect{|a| a.inner_html }.inject(:+) end |