Class: Juknife::Scraping::DSL::Scope

Inherits:
Object
  • Object
show all
Includes:
Juknife::Scraping::DSL
Defined in:
lib/juknife/scraping/dsl/scope.rb

Overview

A DSL node in the tree that makes an scope of element.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Juknife::Scraping::DSL

#children, #item, #items, #scope

Constructor Details

#initialize(selector, *args, &block) ⇒ Scope

Returns a new instance of Scope.



12
13
14
15
16
17
18
# File 'lib/juknife/scraping/dsl/scope.rb', line 12

def initialize(selector, *args, &block)
  @selector = selector
  @args = args

  return unless block
  instance_eval(&block)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



10
11
12
# File 'lib/juknife/scraping/dsl/scope.rb', line 10

def args
  @args
end

#selectorObject (readonly)

Returns the value of attribute selector.



10
11
12
# File 'lib/juknife/scraping/dsl/scope.rb', line 10

def selector
  @selector
end

Instance Method Details

#visit(context) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/juknife/scraping/dsl/scope.rb', line 20

def visit(context)
  scope = context.find(selector)

  children.each do |child|
    child.visit(Context.new(scope, context.result))
  end
end