Class: Lookup::Api
- Inherits:
-
LookupBase
- Object
- ActiveRecord::Base
- LookupBase
- Lookup::Api
- Defined in:
- lib/lookup/models.rb
Instance Method Summary collapse
Instance Method Details
#update_classes! ⇒ Object
56 57 58 59 60 61 |
# File 'lib/lookup/models.rb', line 56 def update_classes! doc = Nokogiri::HTML(Net::HTTP.get(URI.parse("#{url}/fr_class_index.html"))) doc.css("a").each do |a| constant = self.constants.find_or_create_by_name_and_url(a.text, self.url + "/" + a["href"]) end end |
#update_methods! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lookup/models.rb', line 25 def update_methods! entries = [] constants = [] doc = Net::HTTP.get(URI.parse("#{url}/fr_method_index.html")) # Actual HTML on Ruby doc site is invalid. # This makes it valid. doc = Nokogiri::HTML(doc.gsub(/<a(.*?)>(.*?)<\/a>/m) { "<a#{$1}>#{$2.gsub("<", "<").gsub(">", ">")}" }) doc.css("a").each do |a| names = a.text.split(" ") next if names.empty? method = names[0] constant = names[1].gsub(/[\(|\)]/, "") # The same constant can be defined twice in different APIs, be wary! url = self.url + "/classes/" + constant.gsub("::", "/") + ".html" constant = self.constants.find_or_create_by_name_and_url(constant, url) if !/^http:\/\//.match(a["href"]) url = self.url + "/" + a["href"] else url = a["href"] end constant.entries.find_or_create_by_name_and_url(method, url) end # entries.each_slice(100) do |methods| # LookupBase.connection.execute("INSERT INTO entries (name, url) ") # end end |