Skip to content
Browse files

Improvements to the numeric formats and numerify method to differenti…

…ate between values than can or cannot be zero
  • Loading branch information...
1 parent f6e22c7 commit 8c6fc70a60c97bcfe593b4874308671b9f3dfd02 @chrismhilton chrismhilton committed Apr 30, 2012
Showing with 100 additions and 81 deletions.
  1. +3 −1 lib/faker.rb
  2. +1 −1 lib/faker/internet.rb
  3. +3 −3 lib/locales/de-ch.yml
  4. +73 −73 lib/locales/en-gb.yml
  5. +3 −3 lib/locales/nl.yml
  6. +4 −0 test/test_faker.rb
  7. +13 −0 test/test_faker_internet.rb
View
4 lib/faker.rb
@@ -20,8 +20,10 @@ def self.locale=(locale)
class Base
class << self
+
+ # Substitutes '$' for 1-9 and '#' for 0-9
def numerify(number_string)
- number_string.gsub(/#/) { rand(10).to_s }
+ number_string.gsub(/\$/) { (rand(9) + 1).to_s }.gsub(/#/) { rand(10).to_s }
end
def letterify(letter_string)
View
2 lib/faker/internet.rb
@@ -26,7 +26,7 @@ def domain_name(domain = nil)
end
def domain_word(name = nil)
- name = Company.name if name.blank?
+ name = Company.name if name.nil?
name.split(' ').first.gsub(/\W/, '').downcase
end
View
6 lib/locales/de-ch.yml
@@ -2,12 +2,12 @@ de-ch:
faker:
address:
country_code: [CH, CH, CH, DE, AT, US, LI, US, HK, VN]
- postcode: ['1###', '2###', '3###', '4###', '5###', '6###', '7###', '8###', '9###']
+ postcode: ['$###']
company:
suffix: [AG, GmbH, und Söhne, und Partner, "& Co.", Gruppe, LLC, Inc.]
internet:
domain_suffix: [com, net, biz, ch, de, li, at, ch, ch]
phone_number:
- formats: ['0800 ### ###', '0800 ## ## ##', '0## ### ## ##', '0## ### ## ##', '+41 ## ### ## ##', '0900 ### ###', '076 ### ## ##', '+4178 ### ## ##', '0041 79 ### ## ##']
+ formats: ['0800 $## ###', '0800 $# ## ##', '0$# $## ## ##', '0$# $## ## ##', '+41 #$ $## ## ##', '0900 ### ###', '076 ### ## ##', '+4178 ### ## ##', '0041 79 ### ## ##']
cell_phone:
- formats: ['0800 ### ###', '0800 ## ## ##', '0## ### ## ##', '0## ### ## ##', '+41 ## ### ## ##', '0900 ### ###', '076 ### ## ##', '+4178 ### ## ##', '0041 79 ### ## ##']
+ formats: ['0800 $## ###', '0800 $# ## ##', '0$# $## ## ##', '0$# $## ## ##', '+41 #$ $## ## ##', '0900 ### ###', '076 ### ## ##', '+4178 ### ## ##', '0041 79 ### ## ##']
View
146 lib/locales/en-gb.yml
@@ -3,10 +3,10 @@ en-gb:
address:
city_prefix: [North, East, West, South, Great, Great, Little, Long, Thorpe, Upper, Lower]
city_suffix: [town, ton, burgh, borough, bridge, bury, view, port, mouth, chester, mouth, fort, haven, side, shire, land, hampton, ford, hill, ham]
- street_address: ['#', '##', '###']
+ street_address: ['$', '$#', '$##']
street_suffix: [Alley, Avenue, Bank, Banks, Bridge, Brook, Brooks, Cliff, Cliffs, Close, Common, Corner, Court, Courts, Crescent, Crest, Croft, Crossing, Dale, Drive, Drives, End, Estate, Field, Fields, Garden, Gardens, Green, Grove, Groves, Heights, Highway, Hill, Hills, Manor, Meadow, Meadows, Mews, Park, Parks, Place, Road, Row, Rows, Square, Squares, Street, Terrace, Terraces, View, Views, Walk, Walks, Way]
- secondary_address: ['Flat #', 'Flat ##', 'Unit #', 'Unit ##', 'Unit ##']
- postcode: ['??# #??', '??## #??']
+ secondary_address: ['Flat $', 'Flat $#', 'Unit $', 'Unit $#', 'Unit $#']
+ postcode: ['??$ $??', '??$# $??']
# counties in alphabetical order
uk_county: [Anglesey, Ayrshire, Bedfordshire, Berkshire, Brecknockshire, Buckinghamshire, Caernarfonshire, Caithness, Carmarthenshire, Cambridgeshire, Cheshire, Cleveland, Cornwall, County Antrim, County Armagh, County Down, County Fermanagh, County Londonderry, County Tyrone, Denbighshire, Derbyshire, Devon, Dorset, Dunbartonshire, Dumfriesshire, Durham, East Sussex, Essex, Flintshire, Glamorgan, Gloucestershire, Greater Manchester, Hampshire, Hertfordshire, Humberside, Kent, Lancashire, Leicestershire, Lincolnshire, Merseyside, Midlothian, Norfolk, Northamptonshire, Northumberland, Nottinghamshire, Oxfordshire, Rutland, Shropshire, Somerset, Staffordshire, Suffolk, Surrey, Tyne and Wear, Warwickshire, West Sussex, Worcestershire, Yorkshire]
# cities in county order (same index)
@@ -49,76 +49,76 @@ en-gb:
- :last_name
phone_number:
formats: [
- '(01###) ###-###',
- '(01###) ### ###',
- '(01###) ######',
- '01###-###-###',
- '01###-######',
- '01### ######',
- '01### ### ###',
- '01#########',
- '(01##) ###-####',
- '(01##) ### ####',
- '(01##) #######',
- '01##-###-####',
- '01##-#######',
- '01## #######',
- '01## ### ####',
- '+44 (0) 1###-###-###',
- '+44 (0) 1### ### ###',
- '+44 (0) 1### ######',
- '+44 (0) 1### ### ###',
- '+44 (0) 1##-###-####',
- '+44 (0) 1## ### ####',
- '+44 (0) 1## #######',
- '+44 (0) 1## ### ####',
- '+44 (0) 1#########',
- '(01###) ###-### ext ###',
- '(01###) ### ### ext ###',
- '(01###) ###### ext ###',
- '01###-###-### ext ###',
- '01###-###### ext ###',
- '01### ###### ext ###',
- '01######### ext ###',
- '(01##) ###-#### ext ###',
- '(01##) ### #### ext ###',
- '(01##) ####### ext ###',
- '01##-###-#### ext ###',
- '01##-####### ext ###',
- '01## ### #### ext ###',
- '+44 (0) 1###-###-### ext ###',
- '+44 (0) 1### ### ### ext ###',
- '+44 (0) 1### ###### ext ###',
- '+44 (0) 1##-###-#### ext ###',
- '+44 (0) 1## ### #### ext ###',
- '+44 (0) 1## ####### ext ###',
- '+44 (0) 1######### ext ###',
- '(0800) ###-####',
- '(0800) ### ####',
- '(0800) #######',
- '0800-###-####',
- '0800-#######',
- '0800 #######',
- '0800#######',
- '(0845) ###-####',
- '(0845) ### ####',
- '(0845) #######',
- '0845-###-####',
- '0845-#######',
- '0845 #######',
- '0845#######']
+ '(01$##) $##-###',
+ '(01$##) $## ###',
+ '(01$##) $#####',
+ '01$##-$##-###',
+ '01$##-$#####',
+ '01$## $#####',
+ '01$## $## ###',
+ '01$##$#####',
+ '(01$#) $##-####',
+ '(01$#) $## ####',
+ '(01$#) $######',
+ '01$#-$##-####',
+ '01$#-$######',
+ '01$# $######',
+ '01$# $## ####',
+ '+44 (0) 1$##-###-###',
+ '+44 (0) 1$## ### ###',
+ '+44 (0) 1$## ######',
+ '+44 (0) 1$## ### ###',
+ '+44 (0) 1$#-###-####',
+ '+44 (0) 1$# ### ####',
+ '+44 (0) 1$# #######',
+ '+44 (0) 1$# ### ####',
+ '+44 (0) 1$########',
+ '(01$##) $##-### ext $##',
+ '(01$##) $## ### ext $##',
+ '(01$##) $##### ext $##',
+ '01$##-$##-### ext $##',
+ '01$##-$##### ext $##',
+ '01$## $##### ext $##',
+ '01$##$##### ext $##',
+ '(01$#) $##-#### ext $##',
+ '(01$#) $## #### ext $##',
+ '(01$#) $###### ext $##',
+ '01$#-$##-#### ext $##',
+ '01$#-$###### ext $##',
+ '01$# $## #### ext $##',
+ '+44 (0) 1$##-$##-### ext $##',
+ '+44 (0) 1$## $## ### ext $##',
+ '+44 (0) 1$## $##### ext $##',
+ '+44 (0) 1$#-$##-#### ext $##',
+ '+44 (0) 1$# $## #### ext $##',
+ '+44 (0) 1$# $###### ext $##',
+ '+44 (0) 1$#$###### ext $##',
+ '(0800) $##-####',
+ '(0800) $## ####',
+ '(0800) $######',
+ '0800-$##-####',
+ '0800-$######',
+ '0800 $######',
+ '0800$######',
+ '(0845) $##-####',
+ '(0845) $## ####',
+ '(0845) $######',
+ '0845-$##-####',
+ '0845-$######',
+ '0845 $######',
+ '0845$######']
cell_phone:
formats: [
- '(07###) ###-###',
- '(07###) ### ###',
- '(07###) ######',
- '07###-###-###',
- '07###-######',
- '07### ######',
- '07### ### ###',
- '07#########',
- '+44 (0) 7###-###-###',
- '+44 (0) 7### ### ###',
- '+44 (0) 7### ######',
- '+44 (0) 7#########']
+ '(07$##) $##-###',
+ '(07$##) $## ###',
+ '(07$##) $#####',
+ '07$##-$##-###',
+ '07$##-$#####',
+ '07$## $#####',
+ '07$## $## ###',
+ '07$##$#####',
+ '+44 (0) 7$##-$##-###',
+ '+44 (0) 7$## $## ###',
+ '+44 (0) 7$## $#####',
+ '+44 (0) 7$##$#####']
View
6 lib/locales/nl.yml
@@ -34,7 +34,7 @@ nl:
street_suffix: ["straat", "laan", "weg", "plantsoen", "park"]
secondary_address: ["1 hoog", "2 hoog", "3 hoog", "I", "II", "III", "a", "b", "c"]
# Though these are US-specific, they are here (in the default locale) for backwards compatibility
- postcode: ["#### ??"]
+ postcode: ["$### ??"]
state: ["Noord-Holland", "Zuid-Holland", "Utrecht", "Zeeland", "Overijssel", "Gelderland", "Drenthe", "Friesland", "Groningen", "Noord-Braband", "Limburg"]
company:
suffix: [BV, V.O.F., Group, en Zonen]
@@ -73,6 +73,6 @@ nl:
- :middle_name
- :last_name
phone_number:
- formats: ["(####) ######", "##########", "06########", "06 #### ####"]
+ formats: ["(#$##) $#####", "#$########", "06########", "06 #### ####"]
cell_phone:
- formats: ["(####) ######", "##########", "06########", "06 #### ####"]
+ formats: ["(#$##) $#####", "#$########", "06########", "06 #### ####"]
View
4 test/test_faker.rb
@@ -8,4 +8,8 @@ def setup
def test_numerify
assert Faker::Base.numerify('###').match(/\d{3}/)
end
+
+ def test_numerify_positive
+ assert Faker::Base.numerify('$#$').match(/\d{3}/)
+ end
end
View
13 test/test_faker_internet.rb
@@ -30,6 +30,10 @@ def test_domain_word
assert @tester.domain_word.match(/^\w+$/)
end
+ def test_domain_word_with_arg
+ assert @tester.domain_word(Faker::Company.name).match(/^\w+$/)
+ end
+
def test_domain_suffix
assert @tester.domain_suffix.match(/^\w+(\.\w+)?/)
end
@@ -49,4 +53,13 @@ def test_ip_v6_address
assert @tester.ip_v6_address.split('.').map{|h| "0x#{h}".hex}.max <= 65535
end
end
+
+ def test_website
+ assert @tester.website.match(/^((http|https?:\/\/)?((?:[-a-z0-9]+\.)+[a-z]{2,}))$/)
+ end
+
+ def test_website_with_arg
+ assert @tester.website(Faker::Company.name).match(/^((http|https?:\/\/)?((?:[-a-z0-9]+\.)+[a-z]{2,}))$/)
+ end
+
end

0 comments on commit 8c6fc70

Please sign in to comment.
Something went wrong with that request. Please try again.