Class: PhoneSystem::PhoneNumber
- Inherits:
-
Object
- Object
- PhoneSystem::PhoneNumber
- Defined in:
- lib/gts/utils/phone_system.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other_phone_number) ⇒ Object
- #[](attr) ⇒ Object
- #area_code ⇒ Object
- #area_name ⇒ Object
- #country ⇒ Object
- #country_code ⇒ Object
-
#initialize(pstring = nil, options = {}) ⇒ PhoneNumber
constructor
A new instance of PhoneNumber.
- #long ⇒ Object
- #number ⇒ Object
- #short ⇒ Object
- #text ⇒ Object
- #text=(pstring) ⇒ Object
- #to_hash ⇒ Object
- #valid? ⇒ Boolean
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, = {}) @phone_number = {} @phone_number = PhoneSystem::Parser.parse(pstring,) 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, ={}) if nr = PhoneSystem::Parser.parse(pstring, ) return "+#{nr[:country_code]} #{nr[:area_code]} #{nr[:number]}" else return false end end |
.valid?(pstring, options = {}) ⇒ Boolean
151 152 153 |
# File 'lib/gts/utils/phone_system.rb', line 151 def self.valid?(pstring, = {}) !!PhoneSystem::Parser.parse(pstring, ) 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_code ⇒ Object
172 173 174 |
# File 'lib/gts/utils/phone_system.rb', line 172 def area_code @phone_number[:area_code] end |
#area_name ⇒ Object
176 177 178 |
# File 'lib/gts/utils/phone_system.rb', line 176 def area_name @phone_number[:area_name] end |
#country ⇒ Object
168 169 170 |
# File 'lib/gts/utils/phone_system.rb', line 168 def country @phone_number[:country] end |
#country_code ⇒ Object
164 165 166 |
# File 'lib/gts/utils/phone_system.rb', line 164 def country_code @phone_number[:country_code] end |
#long ⇒ Object
196 197 198 |
# File 'lib/gts/utils/phone_system.rb', line 196 def long "+#{country_code} #{area_code} #{number}" end |
#number ⇒ Object
184 185 186 |
# File 'lib/gts/utils/phone_system.rb', line 184 def number @phone_number[:number] end |
#short ⇒ Object
208 209 210 |
# File 'lib/gts/utils/phone_system.rb', line 208 def short "0#{area_code}/#{number}" end |
#text ⇒ Object
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_hash ⇒ Object
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
155 156 157 |
# File 'lib/gts/utils/phone_system.rb', line 155 def valid? PhoneNumber.valid? self.long end |