Class: Scraprr::AttributeScraper
- Inherits:
-
Object
- Object
- Scraprr::AttributeScraper
- Defined in:
- lib/scraprr/attribute_scraper.rb
Constant Summary collapse
- DEFAULT_PATH =
'.'
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
Instance Method Summary collapse
- #build_chain(opts) ⇒ Object
- #eql?(other) ⇒ Boolean
- #extract(element) ⇒ Object
- #hash ⇒ Object
-
#initialize(name, path = DEFAULT_PATH, opts = {}) ⇒ AttributeScraper
constructor
A new instance of AttributeScraper.
Constructor Details
#initialize(name, path = DEFAULT_PATH, opts = {}) ⇒ AttributeScraper
Returns a new instance of AttributeScraper.
7 8 9 10 11 |
# File 'lib/scraprr/attribute_scraper.rb', line 7 def initialize(name, path = DEFAULT_PATH, opts = {}) @name = name @path = path @chain = build_chain(opts) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/scraprr/attribute_scraper.rb', line 3 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/scraprr/attribute_scraper.rb', line 3 def path @path end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
3 4 5 |
# File 'lib/scraprr/attribute_scraper.rb', line 3 def required @required end |
Instance Method Details
#build_chain(opts) ⇒ Object
13 14 15 16 17 18 19 |
# 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) ⇒ Boolean
25 26 27 |
# File 'lib/scraprr/attribute_scraper.rb', line 25 def eql?(other) name.eql?(other.name) end |
#extract(element) ⇒ Object
21 22 23 |
# File 'lib/scraprr/attribute_scraper.rb', line 21 def extract(element) @chain.run(element) end |
#hash ⇒ Object
29 30 31 |
# File 'lib/scraprr/attribute_scraper.rb', line 29 def hash name.hash end |