Class: Juknife::Scraping::DSL::Item
- Inherits:
-
Object
- Object
- Juknife::Scraping::DSL::Item
- Includes:
- Juknife::Scraping::DSL
- Defined in:
- lib/juknife/scraping/dsl/item.rb
Overview
A DSL node in the tree that scrapes an element.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, selector, type = :string, *args, &block) ⇒ Item
constructor
A new instance of Item.
- #visit(context) ⇒ Object
Methods included from Juknife::Scraping::DSL
#children, #item, #items, #scope
Constructor Details
#initialize(name, selector, type = :string, *args, &block) ⇒ Item
Returns a new instance of Item.
12 13 14 15 16 17 18 19 20 |
# File 'lib/juknife/scraping/dsl/item.rb', line 12 def initialize(name, selector, type = :string, *args, &block) @name = name @selector = selector @type = type @args = args return unless block instance_eval(&block) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/juknife/scraping/dsl/item.rb', line 10 def name @name end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
10 11 12 |
# File 'lib/juknife/scraping/dsl/item.rb', line 10 def selector @selector end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/juknife/scraping/dsl/item.rb', line 10 def type @type end |
Instance Method Details
#visit(context) ⇒ Object
22 23 24 |
# File 'lib/juknife/scraping/dsl/item.rb', line 22 def visit(context) context.result[name] = context.text(selector) end |