Class: Scraping::Rules::ElementsOf

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/scraping/rules/elements_of.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL

#element, #elements, #elements_of, #rules

Constructor Details

#initialize(name) ⇒ ElementsOf

Returns a new instance of ElementsOf.



9
10
11
# File 'lib/scraping/rules/elements_of.rb', line 9

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/scraping/rules/elements_of.rb', line 7

def name
  @name
end

Instance Method Details

#call(scraper, node) ⇒ Object



18
19
20
21
22
23
# File 'lib/scraping/rules/elements_of.rb', line 18

def call(scraper, node)
  rules.inject(OpenStruct.new) do |obj, (name, rule)|
    obj[name] = rule.call(scraper, node)
    obj
  end
end

#evaluate(&block) ⇒ Object



13
14
15
16
# File 'lib/scraping/rules/elements_of.rb', line 13

def evaluate(&block)
  instance_eval(&block)
  self
end