Permalink
Browse files

rename `klass` to `delegate` internally to better reflect what this o…

…bject is
  • Loading branch information...
1 parent 5925eb2 commit 065aa34f8016dea2a5dd5f84a1c467331ee60eb3 @mislav committed Oct 24, 2009
Showing with 11 additions and 11 deletions.
  1. +11 −11 scraper.rb
View
22 scraper.rb
@@ -44,8 +44,8 @@ def self.parse(html)
# Specify a new singular scraping rule
def self.element(selector)
- selector, name, klass = parse_rule_declaration(selector)
- rules[name] = [selector, klass]
+ selector, name, delegate = parse_rule_declaration(selector)
+ rules[name] = [selector, delegate]
attr_accessor name
name
end
@@ -58,24 +58,24 @@ def self.elements(selector)
# Let it do its thing!
def parse
- self.class.rules.each do |target, (selector, klass, plural)|
+ self.class.rules.each do |target, (selector, delegate, plural)|
if plural
@doc.search(selector).each do |node|
- send(target) << parse_result(node, klass)
+ send(target) << parse_result(node, delegate)
end
elsif node = @doc.at(selector)
- send("#{target}=", parse_result(node, klass))
+ send("#{target}=", parse_result(node, delegate))
end
end
self
end
protected
- # `klass` is optional, but should respond to `call` or `parse`
- def parse_result(node, klass)
- if klass
- klass.respond_to?(:call) ? klass.call(node) : klass.parse(node)
+ # `delegate` is optional, but should respond to `call` or `parse`
+ def parse_result(node, delegate)
+ if delegate
+ delegate.respond_to?(:call) ? delegate.call(node) : delegate.parse(node)
elsif node.respond_to? :inner_text
node.inner_text
else
@@ -92,8 +92,8 @@ def parse_result(node, klass)
# #=> ['title', :title, nil]
def self.parse_rule_declaration(selector)
if Hash === selector
- klass = selector.delete(:with)
- selector.to_a.flatten << klass
+ delegate = selector.delete(:with)
+ selector.to_a.flatten << delegate
else
[selector.to_s, selector.to_sym, nil]
end

0 comments on commit 065aa34

Please sign in to comment.