module RFastRFurious

Constants

ERRORS
REGEX
SOURCE
VERSION

Public Class Methods

check(string, url = SOURCE) click to toggle source
# File lib/r_fast_r_furious.rb, line 14
def check(string, url = SOURCE)
  uri = URI.parse(SOURCE)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)
  content = response.body
  cxt = if RUBY_PLATFORM == "java" # JRuby
    require "rhino"
    Rhino::Context.new
  else
    require "v8"
    V8::Context.new
  end
  cxt.eval(content, "fast.js")
  cxt["r_fast_r_furious"].call(string)
rescue *ERRORS
  offline_check(string)
end
offline_check(string) click to toggle source
# File lib/r_fast_r_furious.rb, line 9
def offline_check(string)
  !!REGEX.match(string)
end

Private Instance Methods

check(string, url = SOURCE) click to toggle source
# File lib/r_fast_r_furious.rb, line 14
def check(string, url = SOURCE)
  uri = URI.parse(SOURCE)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)
  content = response.body
  cxt = if RUBY_PLATFORM == "java" # JRuby
    require "rhino"
    Rhino::Context.new
  else
    require "v8"
    V8::Context.new
  end
  cxt.eval(content, "fast.js")
  cxt["r_fast_r_furious"].call(string)
rescue *ERRORS
  offline_check(string)
end
offline_check(string) click to toggle source
# File lib/r_fast_r_furious.rb, line 9
def offline_check(string)
  !!REGEX.match(string)
end