Skip to content

Commit

Permalink
Add Faker::Address.country_name_to_code(name: 'united_states') (#1466)
Browse files Browse the repository at this point in the history
* Add country_name to code - Faker::Address

* Update CHANGELOG.md

* Fix address locale
  • Loading branch information
vbrazo authored Nov 9, 2018
1 parent e0eb46a commit 8047aad
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
- [PR #1329](https://github.com/stympy/faker/pull/1329) Update docs on behavior of price [@softwaregravy](https://github.com/softwaregravy)

### Feature Request
- [PR #1466](https://github.com/stympy/faker/pull/1466) Add Faker::Address.country_name_to_code(name: 'united_states') [@vbrazo](https://github.com/vbrazo)
- [PR #1465](https://github.com/stympy/faker/pull/1465) Add Faker.country(country_code: nil) [@vbrazo](https://github.com/vbrazo)
- [PR #1460](https://github.com/stympy/faker/pull/1460) Add Faker::Marketing [@susiirwin](https://github.com/susiirwin)
- [PR #1451](https://github.com/stympy/faker/pull/1451) Add first name 'Simão' and title prefix to 'Eng.' [@jellyfunk](https://github.com/jellyfunk)
Expand Down
8 changes: 6 additions & 2 deletions doc/unreleased/address.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ Faker::Address.state #=> "California"

Faker::Address.state_abbr #=> "AP"

# Optional arguments: code
Faker::Address.country #=> "French Guiana"
Faker::Address.country(code: 'NL') #=> "Netherlands"

# Optional arguments: code
Faker::Address.country_by_code(code: 'NL') #=> "Netherlands"

# Optional arguments: name
Faker::Address.country_name_to_code(name: 'united_states') #=> "US"

Faker::Address.country_code #=> "IT"

Expand Down
12 changes: 10 additions & 2 deletions lib/faker/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,16 @@ def state
fetch('address.state')
end

def country(code: nil)
code.nil? ? fetch('address.country') : fetch('address.country_by_code.' + code)
def country
fetch('address.country')
end

def country_by_code(code: 'US')
fetch('address.country_by_code.' + code)
end

def country_name_to_code(name: 'united_states')
fetch('address.country_by_name.' + name)
end

def country_code
Expand Down
242 changes: 242 additions & 0 deletions lib/locales/en/address.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,248 @@ en:
YE: "Yemen"
ZM: "Zambia"
ZW: "Zimbabwe"
country_by_name:
afghanistan: "AF"
albania: "AB"
algeria: "DZ"
american_samoa: "AS"
andorra: "AD"
angola: "AO"
anguilla: "AI"
antarctica: "AQ"
antigua_and_barbuda: "AG"
argentina: "AR"
armenia: "AM"
aruba: "AW"
australia: "AU"
austria: "AT"
azerbaijan: "AZ"
bahamas: "BS"
bahrain: "BH"
bangladesh: "BD"
barbados: "BB"
belarus: "BY"
belgium: "BE"
belize: "BZ"
benin: "BJ"
bermuda: "BM"
bhutan: "BT"
bolivia: "BO"
bosnia_and_herzegovina: "BA"
botswana: "BW"
bouvet_island: "BV"
brazil: "BR"
british_indian_ocean_territory: "IO"
brunei_darussalam: "BN"
bulgaria: "BG"
burkina_faso: "BF"
burundi: "BI"
cambodia: "KH"
cameroon: "CM"
canada: "CA"
cape_verde: "CV"
cayman_islands: "KY"
central_african_republic: "CF"
chad: "TD"
chile: "CL"
china: "CN"
christmas_island: "CX"
cocos_islands: "CC"
colombia: "CO"
comoros: "KM"
congo: "CG"
cook_islands: "CK"
costa_rica: "CR"
cote_d_ivoire: "CI"
croatia: "HR"
cuba: "CU"
cyprus: "CY"
czech_republic: "CZ"
denmark: "DK"
djibouti: "DJ"
dominica: "DM"
dominican_republic: "DO"
east_timor: "TP"
ecuador: "EC"
egypt: "EG"
el_salvador: "SV"
equatorial_guinea: "GQ"
eritrea: "ER"
estonia: "EE"
ethiopia: "ET"
falkland_islands: "FK"
malvinas: "FK"
faroe_islands: "FO"
fiji: "FJ"
finland: "FI"
france: "FR"
french_guiana: "GF"
french_polynesia: "PF"
french_southern_territories: "TF"
gabon: "GA"
gambia: "GM"
georgia: "GE"
germany: "DE"
ghana: "GH:"
gibraltar: "GI"
greece: "GR"
greenland: "GL"
grenada: "GD"
guadeloupe: "GP"
guam: "GU"
guatemala: "GT"
guinea: "GN"
guinea_bissau: "GW"
guyana: "GY"
haiti: "HT"
heard_island_and_mcdonald_islands: "HM"
holy_see: "VA"
honduras: "HN"
hong_kong: "HK"
hungary: "HU"
iceland: "IS"
india: "IN"
indonesia: "ID"
ir_islamic_republic_of: "Iran, Islamic Republic Of"
iraq: "IQ"
ireland: "IE"
israel: "IL"
italy: "IT"
jamaica: "JM"
japan: "JP"
jordan: "JO"
kazakstan: "KZ"
kenya: "KE"
kiribati: "KI"
korea_democratic_people_s_republic_of: "KP"
korea_republic_of: "KR"
kosovo: "KV"
kuwait: "KW"
kyrgyzstan: "KG"
lao_people_s_democratic_republic: "LA"
latvia: "LV"
lebanon: "LB"
lesotho: "LS"
liberia: "LR"
libyan_arab_jamahiriya: "LY"
liechtenstein: "LI"
lithuania: "LT"
luxembourg: "LU"
macau: "MO"
macedonia_the_former_yugoslav_republic_of: "MK"
madagascar: "MG"
malawi: "MW"
malaysia: "MY"
maldives: "MV"
mali: "ML"
malta: "MT"
marshall_islands: "MH"
martinique: "MQ"
mauritania: "MR"
mauritius: "MU"
mayotte: "YT"
mexicoMX: ""
micronesia_federated_states_of: "FM"
moldova_republic_of: "MD"
monaco: "MC"
mongolia: "MN"
montserrat: "MS"
montenegro: "ME"
morocco: "MA"
mozambique: "MZ"
myanmar: "MM"
namibia: "NA"
nauru: "NR"
nepal: "NP"
netherlands: "NL"
netherlands_antilles: "AN"
new_caledonia: "NC"
new_zealand: "NZ"
nicaragua: "NI"
niger: "NE"
nigeria: "NG"
niue: "NU"
norfolk_island: "NF"
northern_mariana_islands: "NP"
norway: "NP"
oman: "OM"
pakistan: "PK"
palau: "PW"
palestinian_territory_occupied: "PS"
panama: "PA"
papua_new_guinea: "PG"
paraguay: "PY"
peru: "PE"
philippines: "PH"
pitcairn: "PN"
poland: "PL"
portugal: "PT"
puerto_rico: "PR"
qatar: "QA"
reunion: "RE"
romania: "RO"
russian_federation: "RU"
rwanda: "RW"
saint_helena: "SH"
saint_kitts_and_nevis: "KN"
saint_lucia: "LC"
saint_pierre_and_miquelon: "PM"
saint_vincent_and_the_grenadines: "VC"
samoa: "WS"
san_marino: "SM"
sao_tome_and_principe: "ST"
saudi_arabia: "SA"
senegal: "SN"
serbia: "RS"
seychelles: "SC"
sierra_leone: "SL"
singapore: "SG"
slovakia: "SK"
slovenia: "SI"
solomon Islands: "SB"
somalia: "SO"
south_africa: "ZA"
south_georgia_and_the_south_sandwich_islands: "GS"
spain: "ES"
sri_lanka: "LK"
sudan: "SD"
suriname: "SR"
svalbard_and_jan_mayen: "SJ"
swaziland: "SZ"
sweden: "SE"
switzerland: "CH"
syrian_arab_republic: "SY"
taiwan_province_of_china: "TW"
tajikistan: "TJ"
tanzania_united_republic_of: "TZ"
thailand: "TH"
togo: "TG"
tokelau: "TK"
tonga: "TO"
trinidad_and_tobago: "TT"
tunisia: "TN"
turkey: "TR"
turkmenistan: "TM"
turks_and_caicos_islands: "TC"
tuvalu: "TV"
uganda: "UG"
ukraine: "UA"
united_arab_emirates: ""
united_kingdom: "GB"
united_states: "US"
united_states_minor_outlying_islands: "UM"
uruguay: "UY"
uzbekistan: "UZ"
vanuatu: "VU"
venezuela: "VE"
viet_nam: "VN"
virgin_islands_british: "VG"
virgin_islands_u_s_: "VI"
wallis And Futuna: "WF"
western_sahara: "EH"
yemen: "YE"
zambia: "ZM"
zimbabwe: "ZW"
country_code: ["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"]
country_code_long: ["ABW", "AFG", "AGO", "AIA", "ALA", "ALB", "AND", "ARE", "ARG", "ARM", "ASM", "ATA", "ATF", "ATG", "AUS", "AUT", "AZE", "BDI", "BEL", "BEN", "BES", "BFA", "BGD", "BGR", "BHR", "BHS", "BIH", "BLM", "BLR", "BLZ", "BMU", "BOL", "BRA", "BRB", "BRN", "BTN", "BVT", "BWA", "CAF", "CAN", "CCK", "CHE", "CHL", "CHN", "CIV", "CMR", "COD", "COG", "COK", "COL", "COM", "CPV", "CRI", "CUB", "CUW", "CXR", "CYM", "CYP", "CZE", "DEU", "DJI", "DMA", "DNK", "DOM", "DZA", "ECU", "EGY", "ERI", "ESH", "ESP", "EST", "ETH", "FIN", "FJI", "FLK", "FRA", "FRO", "FSM", "GAB", "GBR", "GEO", "GGY", "GHA", "GIB", "GIN", "GLP", "GMB", "GNB", "GNQ", "GRC", "GRD", "GRL", "GTM", "GUF", "GUM", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", "IDN", "IMN", "IND", "IOT", "IRL", "IRN", "IRQ", "ISL", "ISR", "ITA", "JAM", "JEY", "JOR", "JPN", "KAZ", "KEN", "KGZ", "KHM", "KIR", "KNA", "KOR", "KWT", "LAO", "LBN", "LBR", "LBY", "LCA", "LIE", "LKA", "LSO", "LTU", "LUX", "LVA", "MAC", "MAF", "MAR", "MCO", "MDA", "MDG", "MDV", "MEX", "MHL", "MKD", "MLI", "MLT", "MMR", "MNE", "MNG", "MNP", "MOZ", "MRT", "MSR", "MTQ", "MUS", "MWI", "MYS", "MYT", "NAM", "NCL", "NER", "NFK", "NGA", "NIC", "NIU", "NLD", "NOR", "NPL", "NRU", "NZL", "OMN", "PAK", "PAN", "PCN", "PER", "PHL", "PLW", "PNG", "POL", "PRI", "PRK", "PRT", "PRY", "PSE", "PYF", "QAT", "REU", "ROU", "RUS", "RWA", "SAU", "SDN", "SEN", "SGP", "SGS", "SHN", "SJM", "SLB", "SLE", "SLV", "SMR", "SOM", "SPM", "SRB", "SSD", "STP", "SUR", "SVK", "SVN", "SWE", "SWZ", "SXM", "SYC", "SYR", "TCA", "TCD", "TGO", "THA", "TJK", "TKL", "TKM", "TLS", "TON", "TTO", "TUN", "TUR", "TUV", "TWN", "TZA", "UGA", "UKR", "UMI", "URY", "USA", "UZB", "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", "WSM", "YEM", "ZAF", "ZMB", "ZWE"]
building_number: ['#####', '####', '###']
Expand Down
6 changes: 5 additions & 1 deletion test/test_faker_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ def test_country
end

def test_country_by_code
assert @tester.country(code: 'NL').match('Netherlands')
assert @tester.country_by_code(code: 'NL').match('Netherlands')
end

def test_country_name_to_code
assert @tester.country_name_to_code(name: 'united_states').match('US')
end

def test_country_code
Expand Down

0 comments on commit 8047aad

Please sign in to comment.