Class: PhoneSystem::PhoneNumber

Inherits:
Object
  • Object
show all
Defined in:
lib/gts/utils/phone_system.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pstring = nil, options = {}) ⇒ PhoneNumber

Returns a new instance of PhoneNumber.



159
160
161
162
# File 'lib/gts/utils/phone_system.rb', line 159

def initialize(pstring = nil, options = {})
  @phone_number = {}
  @phone_number = PhoneSystem::Parser.parse(pstring,options) unless (pstring == "" || pstring.nil?)
end

Class Method Details

.parse_and_format_long(pstring, options = {}) ⇒ Object



200
201
202
203
204
205
206
# File 'lib/gts/utils/phone_system.rb', line 200

def self.parse_and_format_long(pstring, options={})
  if nr = PhoneSystem::Parser.parse(pstring, options)
    return "+#{nr[:country_code]} #{nr[:area_code]} #{nr[:number]}"
  else
    return false
  end
end

.valid?(pstring, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/gts/utils/phone_system.rb', line 151

def self.valid?(pstring, options = {})
  !!PhoneSystem::Parser.parse(pstring, options)
end

Instance Method Details

#==(other_phone_number) ⇒ Object



229
230
231
# File 'lib/gts/utils/phone_system.rb', line 229

def ==(other_phone_number)
  self.long = other_phone_number.long
end

#[](attr) ⇒ Object



192
193
194
# File 'lib/gts/utils/phone_system.rb', line 192

def [](attr)
  @phone_number[attr]
end

#area_codeObject



172
173
174
# File 'lib/gts/utils/phone_system.rb', line 172

def area_code
  @phone_number[:area_code]
end

#area_nameObject



176
177
178
# File 'lib/gts/utils/phone_system.rb', line 176

def area_name
  @phone_number[:area_name]
end

#countryObject



168
169
170
# File 'lib/gts/utils/phone_system.rb', line 168

def country
  @phone_number[:country]
end

#country_codeObject



164
165
166
# File 'lib/gts/utils/phone_system.rb', line 164

def country_code
  @phone_number[:country_code]
end

#longObject



196
197
198
# File 'lib/gts/utils/phone_system.rb', line 196

def long
  "+#{country_code} #{area_code} #{number}"
end

#numberObject



184
185
186
# File 'lib/gts/utils/phone_system.rb', line 184

def number
  @phone_number[:number]
end

#shortObject



208
209
210
# File 'lib/gts/utils/phone_system.rb', line 208

def short
  "0#{area_code}/#{number}"      
end

#textObject



188
189
190
# File 'lib/gts/utils/phone_system.rb', line 188

def text
  @phone_number[:text]
end

#text=(pstring) ⇒ Object



212
213
214
# File 'lib/gts/utils/phone_system.rb', line 212

def text=(pstring)
  @phone_number = PhoneSystem::Parser.new.parse(pstring)
end

#to_hashObject



216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/gts/utils/phone_system.rb', line 216

def to_hash
  {
    :text         => text,
    :country_code => country_code,
    :country      => country,
    :area_code    => area_code,
    :area_name    => area_name,
    :number       => number,
    :long         => long,
    :short        => short
  }
end

#valid?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/gts/utils/phone_system.rb', line 155

def valid?
  PhoneNumber.valid? self.long
end