Permalink
Browse files

added cell_phone translator and updated phone_number translator to ex…

…clude extension
  • Loading branch information...
1 parent 5a7b495 commit b93594b91c06031ec92d7ce94fca71590e1aedf4 @cheezy committed Dec 22, 2012
Showing with 23 additions and 2 deletions.
  1. +2 −0 ChangeLog
  2. +2 −1 features/data_magic.feature
  3. +1 −0 features/yaml/example.yml
  4. +18 −1 lib/data_magic/translation.rb
View
2 ChangeLog
@@ -4,6 +4,8 @@
* Added ability for street_address translator to also include secondary address
* Added ability for email_address to accept the name portion of the value
* Added url translator
+ * Added cell_phone translator
+ * Changed phone_number translator so it does not return an extension
=== Version 0.10 / 2012-12-8
* Enhancements
View
3 features/data_magic.feature
@@ -37,7 +37,8 @@ Feature: Functionality of the data_magic gem
And the value for "url" should include "http://"
Scenario: Getting a phone number
- Then the value for "phone" should have a minimum of 1 word
+ Then the value for "phone" should be 1 word long
+ And the value for "cell" should be 1 word long
Scenario: Random phrases
Then the value for "catch_phrase" should exist
View
1 features/yaml/example.yml
@@ -21,6 +21,7 @@ dm:
url: ~url
user_name: ~user_name
phone: ~phone_number
+ cell: ~cell_phone
catch_phrase: ~catch_phrase
words: ~words
sentence: ~sentence
View
19 lib/data_magic/translation.rb
@@ -173,7 +173,16 @@ def user_name
# return a random phone number
#
def phone_number
- Faker::PhoneNumber.phone_number
+ value = Faker::PhoneNumber.phone_number
+ remove_extension(value)
+ end
+
+ #
+ # return a random cell number
+ #
+ def cell_phone
+ value = Faker::PhoneNumber.cell_phone
+ remove_extension(value)
end
#
@@ -205,5 +214,13 @@ def mask(value)
end
result
end
+
+ private
+
+ def remove_extension(phone)
+ index = phone.index('x')
+ phone = phone[0, (index-1)] if index
+ phone
+ end
end
end

0 comments on commit b93594b

Please sign in to comment.