Class: Scraper34

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

Constant Summary collapse

RELEASE_NAME =
'3.4'

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



206
207
208
209
210
211
212
213
# File 'lib/scraper.rb', line 206

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



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/scraper.rb', line 215

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