<commit_before>require 'culerity'
require 'rack'
require 'net/http'

class Webcat::Driver::Culerity
  Response = Struct.new(:body)
  
  attr_reader :app, :rack_server

  def initialize(app)
    @app = app
    @rack_server = Webcat::Server.new(@app)
    @rack_server.boot
  end
  
  def visit(path)
    browser.goto(url(path))
  end
  
  def body
    browser.text
  end

private

  def url(path)
    rack_server.url(path)
  end

  def server
    unless @_server
      @_server = ::Culerity::run_server
      at_exit do
        @_server.close
      end
    end
    @_server
  end
  
  def browser
    unless @_browser
      @_browser = ::Culerity::RemoteBrowserProxy.new server, {:browser => :firefox, :log_level => :off}
      at_exit do
        @_browser.exit
      end
    end
    @_browser
  end

end<commit_msg>Culerity server can be shared across sessions<commit_after>require 'culerity'
require 'rack'
require 'net/http'

class Webcat::Driver::Culerity
  Response = Struct.new(:body)
  
  attr_reader :app, :rack_server

  def self.server
    unless @_server
      @_server = ::Culerity::run_server
      at_exit do
        @_server.close
      end
    end
    @_server
  end

  def initialize(app)
    @app = app
    @rack_server = Webcat::Server.new(@app)
    @rack_server.boot
  end
  
  def visit(path)
    browser.goto(url(path))
  end
  
  def body
    browser.text
  end

private

  def url(path)
    rack_server.url(path)
  end
  
  def browser
    unless @_browser
      @_browser = ::Culerity::RemoteBrowserProxy.new self.class.server, {:browser => :firefox, :log_level => :off}
      at_exit do
        @_browser.exit
      end
    end
    @_browser
  end

end
{'fraction_non_alphanumeric': 0.09964200477326969, 'fraction_numerical': 0.0, 'mean_word_length': 2.5987124463519313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6861461', 'n_tokens_mistral': 603, 'n_tokens_neox': 586, 'n_words': 137}