lib/scrapify/base.rb in scrapify-0.0.5 vs lib/scrapify/base.rb in scrapify-0.0.6

- old
+ new

@@ -23,24 +23,28 @@ def html(url) self.url = url define_finders end - def attribute(name, options={}) + def attribute(name, options={}, &block) add_attribute(name) parser = options[:xpath] ? :xpath : :css selector = options[parser] matcher = /#{options[:regex]}/ if options[:regex] to_array = options[:array] meta_define "#{name}_values" do self.doc ||= parse_html self.doc.send(parser, selector).map do |element| - content = element.content - if matcher - match_data = content.scan(matcher).map &:first - options[:array] ? match_data : match_data.first + if block + yield element else - content.strip + content = element.content + if matcher + match_data = content.scan(matcher).map &:first + options[:array] ? match_data : match_data.first + else + content.strip + end end end end end