Class: AusPhones
- Inherits:
-
Object
- Object
- AusPhones
- Defined in:
- lib/aus_phones.rb,
lib/aus_phones/version.rb
Constant Summary collapse
- CNF =
OpenStruct.new(YAML::load_file(File.join(__dir__, '../config/phones.yml')).deep_symbolize_keys)
- VERSION =
"0.9.1"
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#phone_number ⇒ Object
readonly
Returns the value of attribute phone_number.
Instance Method Summary collapse
- #area_code ⇒ Object
- #carrier ⇒ Object
- #description ⇒ Object
- #dial_domestic ⇒ Object
- #dial_international ⇒ Object
- #dial_local ⇒ Object
- #format_domestic ⇒ Object
- #format_international ⇒ Object
- #format_local ⇒ Object
-
#initialize(input = '') ⇒ AusPhones
constructor
A new instance of AusPhones.
- #is_data? ⇒ Boolean
- #is_emergency? ⇒ Boolean
- #is_fictitious? ⇒ Boolean
- #is_form_valid? ⇒ Boolean
- #is_landline? ⇒ Boolean
- #is_mobile? ⇒ Boolean
- #is_nongeo? ⇒ Boolean
- #is_satellite? ⇒ Boolean
- #is_test? ⇒ Boolean
- #is_valid? ⇒ Boolean
- #is_voip? ⇒ Boolean
- #region ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(input = '') ⇒ AusPhones
Returns a new instance of AusPhones.
11 12 13 14 15 |
# File 'lib/aus_phones.rb', line 11 def initialize(input='') raise RuntimeError.new('Not a string') unless input.is_a? String @input = input @phone_number = build end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
7 8 9 |
# File 'lib/aus_phones.rb', line 7 def input @input end |
#phone_number ⇒ Object (readonly)
Returns the value of attribute phone_number.
7 8 9 |
# File 'lib/aus_phones.rb', line 7 def phone_number @phone_number end |
Instance Method Details
#area_code ⇒ Object
77 78 79 |
# File 'lib/aus_phones.rb', line 77 def area_code phone_number.area_code end |
#carrier ⇒ Object
69 70 71 |
# File 'lib/aus_phones.rb', line 69 def carrier phone_number.carrier end |
#description ⇒ Object
73 74 75 |
# File 'lib/aus_phones.rb', line 73 def description phone_number.description end |
#dial_domestic ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/aus_phones.rb', line 85 def dial_domestic if (phone_number.number.to_s.size == 0) return nil else "#{phone_number.area_code}#{phone_number.number}" end end |
#dial_international ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/aus_phones.rb', line 93 def dial_international if (phone_number.area_code.start_with?('0') || phone_number.number.start_with?('0')) dial = "#{phone_number.area_code}#{phone_number.number}" return dial.sub(/^0/, CNF.prefix) else return nil end end |
#dial_local ⇒ Object
81 82 83 |
# File 'lib/aus_phones.rb', line 81 def dial_local phone_number.number end |
#format_domestic ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/aus_phones.rb', line 124 def format_domestic if phone_number.number.to_s.size == 0 nil else if phone_number.area_code.to_s.size == 0 format_local else "(#{phone_number.area_code}) #{format_local}" end end end |
#format_international ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/aus_phones.rb', line 136 def format_international if phone_number.area_code.start_with?('0') area_code = phone_number.area_code.sub(/^0/, '') number = format_local return "+#{CNF.prefix} (#{area_code}) #{number}" elsif phone_number.number.start_with?('0') number = format_local number = number.sub(/^0/, '') return "+#{CNF.prefix} #{number}" else return nil end end |
#format_local ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/aus_phones.rb', line 102 def format_local if (phone_number.number.to_s.size == 0) return nil elsif (phone_number.number.to_s.size == 12) return phone_number.number.sub(/^([0-9]{4})([0-9]{4})([0-9]{4})$/, '\1 \2 \3') elsif (phone_number.number.to_s.size == 11) return phone_number.number.sub(/^([0-9]{4})([0-9]{3})([0-9]{4})$/, '\1 \2 \3') elsif (phone_number.number.to_s.size == 10) return phone_number.number.sub(/^([0-9]{4})([0-9]{3})([0-9]{3})$/, '\1 \2 \3') elsif (phone_number.number.to_s.size == 9) return phone_number.number.sub(/^([0-9]{3})([0-9]{3})([0-9]{3})$/, '\1 \2 \3') elsif (phone_number.number.to_s.size == 8) return phone_number.number.sub(/^([0-9]{4})([0-9]{4})$/, '\1 \2') elsif (phone_number.number.to_s.size == 7) return phone_number.number.sub(/^([0-9]{3})([0-9]{4})$/, '\1 \2') elsif (phone_number.number.to_s.size == 6) return phone_number.number.sub(/^([0-9]{3})([0-9]{3})$/, '\1 \2') elsif (phone_number.number.to_s.size < 6) return phone_number.number end end |
#is_data? ⇒ Boolean
45 46 47 |
# File 'lib/aus_phones.rb', line 45 def is_data? phone_number.type == 'data' end |
#is_emergency? ⇒ Boolean
25 26 27 |
# File 'lib/aus_phones.rb', line 25 def is_emergency? phone_number.type == 'emergency' end |
#is_fictitious? ⇒ Boolean
57 58 59 |
# File 'lib/aus_phones.rb', line 57 def is_fictitious? phone_number.type == 'fictitious' end |
#is_form_valid? ⇒ Boolean
21 22 23 |
# File 'lib/aus_phones.rb', line 21 def is_form_valid? phone_number.is_form_valid end |
#is_landline? ⇒ Boolean
33 34 35 |
# File 'lib/aus_phones.rb', line 33 def is_landline? phone_number.type == 'landline' end |
#is_mobile? ⇒ Boolean
29 30 31 |
# File 'lib/aus_phones.rb', line 29 def is_mobile? phone_number.type == 'mobile' end |
#is_nongeo? ⇒ Boolean
49 50 51 |
# File 'lib/aus_phones.rb', line 49 def is_nongeo? phone_number.type == 'nongeo' end |
#is_satellite? ⇒ Boolean
37 38 39 |
# File 'lib/aus_phones.rb', line 37 def is_satellite? phone_number.type == 'satellite' end |
#is_test? ⇒ Boolean
53 54 55 |
# File 'lib/aus_phones.rb', line 53 def is_test? phone_number.type == 'test' end |
#is_valid? ⇒ Boolean
17 18 19 |
# File 'lib/aus_phones.rb', line 17 def is_valid? phone_number.is_valid end |
#is_voip? ⇒ Boolean
41 42 43 |
# File 'lib/aus_phones.rb', line 41 def is_voip? phone_number.type == 'voip' end |
#region ⇒ Object
65 66 67 |
# File 'lib/aus_phones.rb', line 65 def region phone_number.region end |
#type ⇒ Object
61 62 63 |
# File 'lib/aus_phones.rb', line 61 def type phone_number.type end |