Class: Raspar::DynamicParser
- Inherits:
-
Object
- Object
- Raspar::DynamicParser
- Includes:
- Parser::ClassMethods, Parser::InstanceMethods
- Defined in:
- lib/raspar/dynamic_parser.rb
Instance Attribute Summary collapse
-
#_current_container_ ⇒ Object
Returns the value of attribute current_container.
-
#collections ⇒ Object
Returns the value of attribute collections.
-
#common_attrs ⇒ Object
Returns the value of attribute common_attrs.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#domain_url ⇒ Object
Returns the value of attribute domain_url.
Attributes included from Parser::InstanceMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ DynamicParser
constructor
A new instance of DynamicParser.
- #parse(html) ⇒ Object
Methods included from Parser::ClassMethods
#_init_parser_, #absolute_url, #attr, #attrs, #collection, #info
Methods included from Parser::InstanceMethods
Constructor Details
permalink #initialize ⇒ DynamicParser
Returns a new instance of DynamicParser.
10 11 12 13 |
# File 'lib/raspar/dynamic_parser.rb', line 10 def initialize @common_attrs = {} @collections = {} end |
Instance Attribute Details
permalink #_current_container_ ⇒ Object
Returns the value of attribute current_container.
7 8 9 |
# File 'lib/raspar/dynamic_parser.rb', line 7 def _current_container_ @_current_container_ end |
permalink #collections ⇒ Object
Returns the value of attribute collections.
7 8 9 |
# File 'lib/raspar/dynamic_parser.rb', line 7 def collections @collections end |
permalink #common_attrs ⇒ Object
Returns the value of attribute common_attrs.
7 8 9 |
# File 'lib/raspar/dynamic_parser.rb', line 7 def common_attrs @common_attrs end |
permalink #domain ⇒ Object
Returns the value of attribute domain.
7 8 9 |
# File 'lib/raspar/dynamic_parser.rb', line 7 def domain @domain end |
permalink #domain_url ⇒ Object
Returns the value of attribute domain_url.
7 8 9 |
# File 'lib/raspar/dynamic_parser.rb', line 7 def domain_url @domain_url end |
Class Method Details
permalink .register(url, selector_map, helper_module = nil) ⇒ Object
[View source]
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/raspar/dynamic_parser.rb', line 19 def self.register(url, selector_map, helper_module = nil) dp = self.new if selector_map[:common_attrs] selector_map[:common_attrs].each { |attr, opts| dp.attr(attr, opts) } end if selector_map[:collections] selector_map[:collections].each do |name, collection_opts| dp.collections[name] = { :select => collection_opts[:select], :attrs => {} } dp._current_container_ = name.to_sym collection_opts[:attrs].each { |attr, opts| dp.attr(attr, opts) } dp._current_container_ = nil end end #TODO: Create constant from string and extend object. dp.extend(helper_module) if helper_module dp.domain_url = url dp.domain = Raspar.register(url, dp) dp end |
Instance Method Details
permalink #parse(html) ⇒ Object
[View source]
15 16 17 |
# File 'lib/raspar/dynamic_parser.rb', line 15 def parse(html) self.process(html, self) end |