Module: Raspar::Parser::ClassMethods
- Included in:
- DynamicParser
- Defined in:
- lib/raspar/parser.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
readonly
Returns the value of attribute collections.
-
#common_attrs ⇒ Object
readonly
Returns the value of attribute common_attrs.
-
#domain(url = nil) ⇒ Object
readonly
Returns the value of attribute domain.
Instance Method Summary collapse
- #_init_parser_ ⇒ Object
- #absolute_url(path) ⇒ Object
-
#attr(name, select = nil, opts = {}, &block) ⇒ Object
name // opts = => nil name, ‘.name’ // opts = => [‘.name’] name, ‘.name, .title’ // opts = => [‘.name’, ‘.title’] name, [‘.name’, .title] // opts = => [‘.name’, ‘.title’] name, ‘.name’, => :parse_name, :attr => ‘name’ opts = => :parse_name, :attr => ‘name’, :select => [‘.name’] name, => :parse_name, :attr => ‘name’ opts = => :parse_name, :attr => ‘name’, :select => nil.
- #attrs ⇒ Object
- #collection(collection_name, select, &block) ⇒ Object
- #info ⇒ Object
- #parse(html) ⇒ Object
Instance Attribute Details
#collections ⇒ Object (readonly)
Returns the value of attribute collections.
5 6 7 |
# File 'lib/raspar/parser.rb', line 5 def collections @collections end |
#common_attrs ⇒ Object (readonly)
Returns the value of attribute common_attrs.
5 6 7 |
# File 'lib/raspar/parser.rb', line 5 def common_attrs @common_attrs end |
#domain(url = nil) ⇒ Object (readonly)
Returns the value of attribute domain.
5 6 7 |
# File 'lib/raspar/parser.rb', line 5 def domain @domain end |
Instance Method Details
#_init_parser_ ⇒ Object
7 8 9 10 |
# File 'lib/raspar/parser.rb', line 7 def _init_parser_ @common_attrs = {} @collections = {} end |
#absolute_url(path) ⇒ Object
65 66 67 |
# File 'lib/raspar/parser.rb', line 65 def absolute_url(path) URI(@domain_url).merge(path).to_s end |
#attr(name, select = nil, opts = {}, &block) ⇒ Object
name // opts = => nil name, ‘.name’ // opts = => [‘.name’] name, ‘.name, .title’ // opts = => [‘.name’, ‘.title’] name, [‘.name’, .title] // opts = => [‘.name’, ‘.title’] name, ‘.name’, => :parse_name, :attr => ‘name’
opts = {:eval => :parse_name, :attr => 'name', :select => ['.name']}
name, => :parse_name, :attr => ‘name’
opts = {:eval => :parse_name, :attr => 'name', :select => nil}
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/raspar/parser.rb', line 21 def attr(name, select = nil, opts = {}, &block) if select.is_a?(Hash) opts = select else opts[:select] = select end opts[:select] = case opts[:select] when Array opts[:select].flatten when String opts[:select].split(',').collect(&:strip) else opts[:select] end opts[:select] = opts[:select].join(',') if opts[:as] == :array opts[:eval] = opts[:eval].to_sym if opts[:eval].is_a?(String) opts[:eval] = block if block_given? if @_current_container_ @collections[@_current_container_][:attrs][name.to_sym] = opts else @common_attrs[name.to_sym] = opts end end |
#attrs ⇒ Object
73 74 75 |
# File 'lib/raspar/parser.rb', line 73 def attrs {:collections => @collections, :common_attrs => @common_attrs} end |
#collection(collection_name, select, &block) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/raspar/parser.rb', line 48 def collection(collection_name, select, &block) collection_name = collection_name.to_sym @collections[collection_name] = { :select => select, :attrs => {} } @_current_container_ = collection_name yield @_current_container_ = nil end |
#info ⇒ Object
77 78 79 |
# File 'lib/raspar/parser.rb', line 77 def info {:domain => @domain, :collections => @collections.keys, :common_attrs => @common_attrs.keys} end |
#parse(html) ⇒ Object
69 70 71 |
# File 'lib/raspar/parser.rb', line 69 def parse(html) self.new.process(html) end |