class LoomioScraper::Scraper

Public Class Methods

html_loader(url) click to toggle source
# File lib/LoomioScraper/helper.rb, line 9
                def self.html_loader(url)
#                       return Nokogiri::HTML(File.open('index.html').read)
                        gem_path = LoomioScraper::home_dir
                        
                        script_path = gem_path + '/lib/LoomioScraper/script.js'
                        file_path = gem_path + '/index.html'
               dom = html = nil
            pid ||= Process.spawn('phantomjs', script_path, url, file_path)
                       Process.waitpid(pid)
    
            html ||= File.open(file_path).read
            File.delete(file_path)
            dom ||= Nokogiri::HTML(html)    
        end
new(url) click to toggle source
# File lib/LoomioScraper/helper.rb, line 4
       def initialize(url)
        @dom = Scraper.html_loader(url)
        @attributes = []
end

Public Instance Methods

attributes() click to toggle source
# File lib/LoomioScraper/helper.rb, line 28
def attributes
        @attributes
end
to_hash() click to toggle source
# File lib/LoomioScraper/helper.rb, line 24
    def to_hash
   @attributes.reduce({}) { |hash, attr| hash[attr.to_sym] = self.send(attr.to_sym); hash }
end