Class: Libphonenumber

Inherits:
Object
  • Object
show all
Defined in:
lib/libphonenumber-execjs/version.rb,
lib/libphonenumber-execjs/libphonenumber.rb

Defined Under Namespace

Classes: Simple

Constant Summary collapse

VERSION =
"0.0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLibphonenumber

Returns a new instance of Libphonenumber.



5
6
7
# File 'lib/libphonenumber-execjs/libphonenumber.rb', line 5

def initialize
  @context = ExecJS.compile(File.read(File.join(File.dirname(__FILE__), "..", "..", "support", "libphonenumber.js")))
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/libphonenumber-execjs/libphonenumber.rb', line 3

def context
  @context
end

Instance Method Details

#extractPossibleNumber(str = "") ⇒ Object



9
10
11
# File 'lib/libphonenumber-execjs/libphonenumber.rb', line 9

def extractPossibleNumber(str="")
  context.call "i18n.phonenumbers.PhoneNumberUtil.extractPossibleNumber", str
end

#normalize(str = "") ⇒ Object



13
14
15
# File 'lib/libphonenumber-execjs/libphonenumber.rb', line 13

def normalize(str="")
  context.call "i18n.phonenumbers.PhoneNumberUtil.normalize", str
end

#parse(str = "", default_region = "ZZ") ⇒ Object



17
18
19
# File 'lib/libphonenumber-execjs/libphonenumber.rb', line 17

def parse(str="", default_region="ZZ")
  context.call "i18n.phonenumbers.PhoneNumberUtil.getInstance().parse", str, default_region
end

#simpleObject



21
22
23
# File 'lib/libphonenumber-execjs/libphonenumber.rb', line 21

def simple
  @simple ||= Simple.new(self)
end