Module: Graboid::Scraper::ClassMethods
- Defined in:
- lib/graboid/scraper.rb
Instance Method Summary collapse
- #callbacks ⇒ Object
- #inferred_selector ⇒ Object
- #inherited(subclass) ⇒ Object
- #inherited_attributes(*args) ⇒ Object
- #page_with(&block) ⇒ Object
- #root_selector ⇒ Object
- #selector(selector) ⇒ Object (also: #root)
- #set(name, opts = {}, &block) ⇒ Object
Instance Method Details
#callbacks ⇒ Object
35 36 37 |
# File 'lib/graboid/scraper.rb', line 35 def callbacks read_inheritable_attribute :callbacks end |
#inferred_selector ⇒ Object
39 40 41 |
# File 'lib/graboid/scraper.rb', line 39 def inferred_selector @inferred_selector ||= ".#{self.to_s.underscore}" end |
#inherited(subclass) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/graboid/scraper.rb', line 28 def inherited(subclass) @inherited_attributes.each do |inheritable_attribute| instance_var = "@#{inheritable_attribute}" subclass.instance_variable_set(instance_var, instance_variable_get(instance_var)) end end |
#inherited_attributes(*args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/graboid/scraper.rb', line 17 def inherited_attributes(*args) @inherited_attributes ||= [:inherited_attributes] @inherited_attributes += args args.each do |arg| class_eval %( class << self; attr_accessor :#{arg} end ) end @inherited_attributes end |
#page_with(&block) ⇒ Object
43 44 45 46 47 |
# File 'lib/graboid/scraper.rb', line 43 def page_with &block define_method :pager do instance_eval &block end end |
#root_selector ⇒ Object
49 50 51 |
# File 'lib/graboid/scraper.rb', line 49 def root_selector @root_selector || inferred_selector end |
#selector(selector) ⇒ Object Also known as: root
53 54 55 |
# File 'lib/graboid/scraper.rb', line 53 def selector selector @root_selector = selector end |
#set(name, opts = {}, &block) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/graboid/scraper.rb', line 59 def set name, opts={}, &block opts.merge!(:selector => ".#{name}") if opts[:selector].nil? opts.merge!(:processor => block) if block_given? attribute_map[name] = opts end |