Class: Scraper32

Inherits:
Scraper show all
Defined in:
lib/scraper.rb

Constant Summary collapse

RELEASE_NAME =
'3.2'

Constants inherited from Scraper

Scraper::BASE_URL, Scraper::HEX_CHARS

Instance Attribute Summary

Attributes inherited from Scraper

#classes_for_method, #hrefs_for_name

Instance Method Summary collapse

Methods inherited from Scraper

#add_class, #add_file, #get_home_page, #initialize, release_names, scrapers, #write_json

Constructor Details

This class inherits a constructor from Scraper

Instance Method Details

#add_method(element) ⇒ Object



248
249
250
251
252
253
254
255
# File 'lib/scraper.rb', line 248

def add_method(element)
  href = element.attributes['href']
  m = href.match(%r[(#)])
  class_name = m.pre_match.gsub('/', '::').sub(%r[\.html$], '')
  new_href = m.post_match
  element.attributes['href'] = new_href
  super(element, class_name)
end

#scrapeObject



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/scraper.rb', line 257

def scrape
  home_page = get_home_page(RELEASE_NAME, 'table_of_contents.html')
  enum = home_page.lines.to_enum
  while true do
    begin
      line = enum.next
      next unless line.match(%r[<li class="(\w+)">])
      type = $1
      next_line = enum.peek
      element = REXML::Document.new(next_line).root
      case type
      when 'file'
        add_file(element)
      when 'class', 'module'
        add_class(element)
      when 'method'
        add_method(element)
      else
        raise type
      end
    rescue StopIteration
      break
    end
  end
  write_json(RELEASE_NAME)
end