Class: Yapra::Plugin::MechanizeBase
- Defined in:
- lib/yapra/plugin/mechanize_base.rb
Constant Summary
Constants included from FeedItemOperator
FeedItemOperator::LOCAL_VAL_RE
Instance Attribute Summary
Attributes included from ContextAware
#pipeline, #plugin_config, #yapra
Instance Method Summary collapse
Methods inherited from Base
Methods included from ErbApplier
Methods included from FeedItemOperator
Methods included from ContextAware
Instance Method Details
#agent ⇒ Object
6 7 8 9 |
# File 'lib/yapra/plugin/mechanize_base.rb', line 6 def agent pipeline.context['mechanize_agent'] ||= (defined?(Mechanize) ? Mechanize.new : WWW::Mechanize.new) pipeline.context['mechanize_agent'] end |
#extract_attribute_from(element, item, binding = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/yapra/plugin/mechanize_base.rb', line 11 def extract_attribute_from element, item, binding=nil if plugin_config['extract_xpath'] plugin_config['extract_xpath'].each do |k, v| value = nil case v.class.to_s when 'String' value = element.search(v).to_html.toutf8 when 'Hash' ele = element.at( v['first_node'] ) value = ( ele.nil? ) ? nil : ele.get_attribute( v['attr'] ) end set_attribute_to item, k, value end end if plugin_config['apply_template_after_extracted'] plugin_config['apply_template_after_extracted'].each do |k, template| value = apply_template template, binding set_attribute_to item, k, value end end end |