Class: Autoweb::ContentParser

Inherits:
Object
  • Object
show all
Defined in:
lib/autoweb/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, page) ⇒ ContentParser

Returns a new instance of ContentParser.



118
119
120
121
# File 'lib/autoweb/page.rb', line 118

def initialize(doc, page)
  @doc = doc
  @page = page
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *args, &block) ⇒ Object



137
138
139
140
141
142
143
# File 'lib/autoweb/page.rb', line 137

def method_missing(key, *args, &block)
  if doc.respond_to?(key)
    doc.send key, *args, &block
  else
    super
  end
end

Instance Attribute Details

#docObject

Returns the value of attribute doc.



116
117
118
# File 'lib/autoweb/page.rb', line 116

def doc
  @doc
end

#pageObject

Returns the value of attribute page.



116
117
118
# File 'lib/autoweb/page.rb', line 116

def page
  @page
end

Instance Method Details

#[](key) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/autoweb/page.rb', line 123

def [](key)
  if r = page.sub_pages[key]
    if r.is_array
      doc.search(r.css).map{|e|self.class.new(e,r)}
    else
      self.new(doc.at(page.css),r)
    end
  elsif r = page.elements[key]
     doc.at(r.css)
  else
    raise "key not found" 
  end
end