Module: Wombat::Parser

Includes:
PropertyLocator
Included in:
Crawler
Defined in:
lib/wombat/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PropertyLocator

#locate

Methods included from NodeSelector

#select_nodes

Instance Attribute Details

#contextObject

Returns the value of attribute context.



9
10
11
# File 'lib/wombat/parser.rb', line 9

def context
  @context
end

#mechanizeObject

Returns the value of attribute mechanize.



9
10
11
# File 'lib/wombat/parser.rb', line 9

def mechanize
  @mechanize
end

Instance Method Details

#initializeObject



11
12
13
# File 'lib/wombat/parser.rb', line 11

def initialize
  @mechanize = Mechanize.new
end

#parse(metadata) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wombat/parser.rb', line 15

def parse 
  self.context = get_parser 
  original_context = self.context

  .iterators.each do |it|
    select_nodes(it.selector).each do |n|
      self.context = n
      it.all_properties.each do |p|
        p.result ||= []
        result = locate(p)
        if result
          result = p.callback ? p.callback.call(result) : result
          p.result << result
        end
      end
    end
  end

  self.context = original_context

  .all_properties.each do |p|
    result = locate p
    p.result = p.callback ? p.callback.call(result) : result
  end

  .flatten
end