Class: WebCrawler::Parsers::Mapper::Map
- Inherits:
-
Object
- Object
- WebCrawler::Parsers::Mapper::Map
- Defined in:
- lib/web_crawler/parsers/mapper.rb
Instance Method Summary collapse
- #call(context) ⇒ Object
- #element ⇒ Object
- #filter ⇒ Object
- #in(context) ⇒ Object
-
#initialize(selector, binding, options, &block) ⇒ Map
constructor
A new instance of Map.
- #on ⇒ Object
- #to(context) ⇒ Object
- #with_block? ⇒ Boolean
Constructor Details
#initialize(selector, binding, options, &block) ⇒ Map
Returns a new instance of Map.
20 21 22 23 24 |
# File 'lib/web_crawler/parsers/mapper.rb', line 20 def initialize(selector, binding, , &block) @selector, @options = selector, self.class..merge() @binding = binding @block = block end |
Instance Method Details
#call(context) ⇒ Object
52 53 54 55 56 |
# File 'lib/web_crawler/parsers/mapper.rb', line 52 def call(context) value = context.search(element) value = value.send(*on) if on.present? filter.call(value) end |
#element ⇒ Object
30 31 32 |
# File 'lib/web_crawler/parsers/mapper.rb', line 30 def element @selector end |
#filter ⇒ Object
48 49 50 |
# File 'lib/web_crawler/parsers/mapper.rb', line 48 def filter @filter ||= Filter.new(@options[:filter], @binding) end |
#in(context) ⇒ Object
34 35 36 37 38 |
# File 'lib/web_crawler/parsers/mapper.rb', line 34 def in(context) context.search(element).each do |el| yield el, @block.call end end |
#on ⇒ Object
40 41 42 |
# File 'lib/web_crawler/parsers/mapper.rb', line 40 def on @options[:on] end |
#to(context) ⇒ Object
44 45 46 |
# File 'lib/web_crawler/parsers/mapper.rb', line 44 def to(context) @options[:to].respond_to?(:call) ? @options[:to].call(context) : @options[:to] end |
#with_block? ⇒ Boolean
26 27 28 |
# File 'lib/web_crawler/parsers/mapper.rb', line 26 def with_block? @block.present? end |