faker-ruby / faker

A library for generating fake data such as names, addresses, and phone numbers.
MIT License
11.22k stars 3.18k forks source link

[Suggestion] Country abbr #328

Closed franciscomxs closed 8 years ago

franciscomxs commented 9 years ago
Faker::Address.country_abbr #=> "BR"
tom-lord commented 9 years ago

This sounds like a case for https://github.com/stympy/faker#customization

Do you want to abbreviate England as "EN", "UK", or "GB"? Is Spain "SP" or "ES"? Do you really want to include ALL countries, or just a subset (e.g. not Bosnia and Herzegovina = "BA")?

My guess is that you really want to either be selecting from a custom list, or just using a random 2 letter string.

franciscomxs commented 9 years ago

Maybe aliasing state_abbr

Em domingo, 8 de março de 2015, Tom Lord notifications@github.com escreveu:

This sounds like a case for https://github.com/stympy/faker#customization

Do you want to abbreviate England as "EN", "UK", or "GB"? Is Spain "SP" or "ES"? Do you really want to include ALL countries, or just a subset (e.g. not Bosnia and Herzegovina = "BA")?

My guess is that you really want to either be selecting from a custom list, or just using a random 2 letter string.

— Reply to this email directly or view it on GitHub https://github.com/stympy/faker/issues/328#issuecomment-77744410.

tom-lord commented 9 years ago

Again, that just sounds like you're looking for "a random 2 letter string". States are not countries, so this would inevitably cause complaints.

Incidentally, if you are happy to just use a random 2 letter string, why not check out my brand new(ish) ruby gem: https://github.com/tom-lord/regexp-examples/tree/random_example

(The random_example branch is not yet merged as it needs a little polishing, so you'll have to wait for v1.1.0 to actually use it, but that should be pretty soon.)

franciscomxs commented 9 years ago

Use Faker::Address.state_abbr is enought. My suggestion is just to improve readability.

Instead of:

Costumer.new(
state:  Faker::Address.state_abbr,
country:  Faker::Address.state_abbr
)

We could have:

Costumer.new(
state:  Faker::Address.state_abbr,
country:  Faker::Address.country_abbr
)
kkirsche commented 9 years ago

@tom-lord I would disagree with your statement that this is a customization option. Two letter codes should follow ISO standards and be labeled as such. For example, a generator for ISO 3166-1 would generate the country codes found here: http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes

tom-lord commented 9 years ago

@kkirsche i agree that this is a possible (not terrible) option, but surely for many - if not most - real world applications, this list would be wrong.

For example, as i mentioned above, using ISO 3166-1, "United Kingdom of Great Britain and Northern Ireland" = "GB". Perhaps your test data actually needs to use "EN" (England) or "UK" (United Kingdom).

Essentially, I'm not really against what you are proposing but i suspect many people would still need to resort to using customization for their specific use case.

tejasbubane commented 8 years ago

We have Faker::Address.country_code right? https://github.com/stympy/faker/blob/master/lib/locales/en.yml#L8

tom-lord commented 8 years ago

Good spot, this was added a long time ago too.

https://github.com/stympy/faker/commit/a1f0bbd2583ad9d232ad2c76f0ae8e72e98c8b53

tejasbubane commented 8 years ago

Yes. I guess we can close the issue then. @franciscomxs

franciscomxs commented 8 years ago

Thank you guys.