module Fakie::JavaScript

Public Instance Methods

call(function, *args) click to toggle source

Call a function against the context @param function [String] function name @param args [* String] list of arguments to send to the function

# File lib/fakie/java_script.rb, line 20
def call(function, *args)
  context.call(function, *args)
end
context() click to toggle source

ExecJS Context @return [ExecJS::ExternalRuntime::Context] context for executing JavaScript against libphonenumber and Fakie

# File lib/fakie/java_script.rb, line 7
def context
  @@_js_context ||= begin
    require 'execjs'
    js_dir = File.join(File.expand_path(File.dirname(__FILE__)), 'js')
    source = File.open(File.join(js_dir, 'libphonenumber.js')).read
    source += File.open(File.join(js_dir, 'fakie.js')).read
    ExecJS.compile(source)
  end
end
eval(script) click to toggle source

Call a function against the context @param function [String] JavaScript code to evaluate

# File lib/fakie/java_script.rb, line 26
def eval(script)
  context.eval(script)
end