Advertisement
Guest User

Untitled

a guest
May 4th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. require 'pry'
  2. class Phone
  3.  
  4. def initialize(number)
  5. @trim = number.gsub(/[^0-9]/, '')
  6. end
  7.  
  8. def number
  9. if @trim.length == 11 && @trim.chars.first == '1'
  10. @trim.slice(1..@trim.length)
  11. elsif @trim.length != 10
  12. @trim = "0000000000"
  13. else
  14. @trim
  15. end
  16. end
  17.  
  18. def area_code
  19. @trim.slice(0..2)
  20. end
  21.  
  22. def to_s
  23. first = @trim.slice(0..2)
  24. second = @trim.slice(3..5)
  25. third = @trim.slice(6..9)
  26.  
  27. return "(#{first}) #{second}-#{third}"
  28. end
  29.  
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement