Module: RFastRFurious

Defined in:
lib/r_fast_r_furious.rb,
lib/r_fast_r_furious/version.rb

Constant Summary collapse

SOURCE =
"https://raw.github.com/alunny/r_fast_r_furious/master/fast.js"
REGEX =
/^((T(he)(?=.*the)|2(?=.* 2)) )?Fast (Five|(((and t\3)|\2(?=.*s$)|&(?!.*:)) Furious(( (6|7))|: Tokyo Drift)?))$/
ERRORS =
[LoadError, SocketError, Timeout::Error]
VERSION =
"2.0.0"

Class Method Summary collapse

Class Method Details

.check(string, url = SOURCE) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



9
10
11
# File 'lib/r_fast_r_furious.rb', line 9

def offline_check(string)
  !!REGEX.match(string)
end