Class: Juknife::Scraping::DSL::Items
- Inherits:
-
Object
- Object
- Juknife::Scraping::DSL::Items
- Includes:
- Juknife::Scraping::DSL
- Defined in:
- lib/juknife/scraping/dsl/items.rb
Overview
A DSL node in the tree that scrapes elements.
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) ⇒ Items
constructor
A new instance of Items.
-
#visit(context) ⇒ Object
rubocop:disable Metrics/AbcSize.
Methods included from Juknife::Scraping::DSL
#children, #item, #items, #scope
Constructor Details
#initialize(name, selector, type = :string, *args, &block) ⇒ Items
Returns a new instance of Items.
15 16 17 18 19 20 21 22 23 |
# File 'lib/juknife/scraping/dsl/items.rb', line 15 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.
13 14 15 |
# File 'lib/juknife/scraping/dsl/items.rb', line 13 def name @name end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
13 14 15 |
# File 'lib/juknife/scraping/dsl/items.rb', line 13 def selector @selector end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/juknife/scraping/dsl/items.rb', line 13 def type @type end |
Instance Method Details
#visit(context) ⇒ Object
rubocop:disable Metrics/AbcSize
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/juknife/scraping/dsl/items.rb', line 25 def visit(context) # rubocop:disable Metrics/AbcSize result = [] context.find_all(selector).each do |ele_chlid| child_context = Context.new(ele_chlid, {}) children.each do |child| child.visit(child_context) end result << child_context.result end context.result[name] = result.reject { |hash| hash.values.compact.all?(&:empty?) } end |