class Scraprr::AttributeScraper

Constants

DEFAULT_PATH

Attributes

name[R]
path[R]
required[R]

Public Class Methods

new(name, path = DEFAULT_PATH, opts = {}) click to toggle source
# File lib/scraprr/attribute_scraper.rb, line 7
def initialize(name, path = DEFAULT_PATH, opts = {})
  @name = name
  @path = path
  @chain = build_chain(opts)
end

Public Instance Methods

build_chain(opts) click to toggle source
# File lib/scraprr/attribute_scraper.rb, line 13
def build_chain(opts)
  chain = ValueExtractor.new(opts[:attr], opts[:html])
  chain = RegexpFilter.new(chain, opts[:regexp]) if opts[:regexp]
  chain = StripFilter.new(chain) if opts[:strip]
  chain = RequiredFilter.new(chain, opts[:name]) if opts[:required]
  chain
end
eql?(other) click to toggle source
# File lib/scraprr/attribute_scraper.rb, line 25
def eql?(other)
  name.eql?(other.name)
end
extract(element) click to toggle source
# File lib/scraprr/attribute_scraper.rb, line 21
def extract(element)
  @chain.run(element)
end
hash() click to toggle source
# File lib/scraprr/attribute_scraper.rb, line 29
def hash
  name.hash
end