Class: Scraprr::ValueExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/scraprr/value_extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(attr, html) ⇒ ValueExtractor

Returns a new instance of ValueExtractor.


3
4
5
6
# File 'lib/scraprr/value_extractor.rb', line 3

def initialize(attr, html)
  @attr = attr
  @html = html
end

Instance Method Details

#run(element) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/scraprr/value_extractor.rb', line 8

def run(element)
  if @attr && element.first
    element.attr(@attr).to_s
  else
    if @html
      element.inner_html
    else
      element.inner_text
    end
  end
end