Class: Mobistar::Number
- Inherits:
-
Object
- Object
- Mobistar::Number
- Defined in:
- lib/mobistar.rb
Instance Method Summary collapse
- #belgian ⇒ Object
- #human(group = 2) ⇒ Object
-
#initialize(string) ⇒ Number
constructor
A new instance of Number.
- #international ⇒ Object
Constructor Details
#initialize(string) ⇒ Number
Returns a new instance of Number.
11 12 13 14 15 16 17 |
# File 'lib/mobistar.rb', line 11 def initialize string if string =~ /^(\+32|0)4([7-9]\d{7})$/ @num = $2 else raise InvalidGSMNumber, "#{string} isn't a valid belgian gsm number !" end end |
Instance Method Details
#belgian ⇒ Object
23 24 25 |
# File 'lib/mobistar.rb', line 23 def belgian "04#{@num}" end |
#human(group = 2) ⇒ Object
27 28 29 |
# File 'lib/mobistar.rb', line 27 def human group=2 "04#{@num[0..1]}/#{@num[2..-1].gsub(/(\d{#{group}})/, '\1.')[0...-1]}" end |
#international ⇒ Object
19 20 21 |
# File 'lib/mobistar.rb', line 19 def international "+324#{@num}" end |