Class: Raspar::DynamicParser

Inherits:
Object
  • Object
show all
Includes:
Parser::ClassMethods, Parser::InstanceMethods
Defined in:
lib/raspar/dynamic_parser.rb

Instance Attribute Summary collapse

Attributes included from Parser::InstanceMethods

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parser::ClassMethods

#_init_parser_, #absolute_url, #attr, #attrs, #collection, #info

Methods included from Parser::InstanceMethods

#attr_parser, #process

Constructor Details

#initializeDynamicParser

Returns a new instance of DynamicParser.

[View source]

10
11
12
13
# File 'lib/raspar/dynamic_parser.rb', line 10

def initialize
  @common_attrs = {}
  @collections = {}
end

Instance Attribute Details

#_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

#collectionsObject

Returns the value of attribute collections.


7
8
9
# File 'lib/raspar/dynamic_parser.rb', line 7

def collections
  @collections
end

#common_attrsObject

Returns the value of attribute common_attrs.


7
8
9
# File 'lib/raspar/dynamic_parser.rb', line 7

def common_attrs
  @common_attrs
end

#domainObject

Returns the value of attribute domain.


7
8
9
# File 'lib/raspar/dynamic_parser.rb', line 7

def domain
  @domain
end

#domain_urlObject

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

.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

#parse(html) ⇒ Object

[View source]

15
16
17
# File 'lib/raspar/dynamic_parser.rb', line 15

def parse(html)
  self.process(html, self)
end