Class: Synthra::Types::AddressLocation::State
- Defined in:
- lib/synthra/types/address_location/locations.rb
Overview
State type
Instance Method Summary collapse
- #generate_edge(rng, context, args) ⇒ Object
- #generate_invalid(rng, context, args) ⇒ Object
-
#generate_random(rng, context, args) ⇒ String
Generate random state/province name.
Instance Method Details
#generate_edge(rng, context, args) ⇒ Object
81 82 83 |
# File 'lib/synthra/types/address_location/locations.rb', line 81 def generate_edge(rng, context, args) ["", "CA", "Very Long State Name That Exceeds Normal Limits"].sample(random: rng.instance_variable_get(:@random)) end |
#generate_invalid(rng, context, args) ⇒ Object
85 86 87 |
# File 'lib/synthra/types/address_location/locations.rb', line 85 def generate_invalid(rng, context, args) [nil, 123, [], {}].sample(random: rng.instance_variable_get(:@random)) end |
#generate_random(rng, context, args) ⇒ String
Generate random state/province name
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/synthra/types/address_location/locations.rb', line 48 def generate_random(rng, context, args) country = (args[:country] || :us).to_sym adapter = faker_adapter(context) if adapter case country when :us adapter.state when :ca adapter.state_abbr # Faker uses state_abbr for Canada else adapter.state end else # Fallback to Faker with default locale case country when :us Faker::Address.state when :ca Faker::Address.state_abbr else Faker::Address.state end end rescue StandardError rng.sample(["California", "New York", "Texas", "Florida", "Illinois"]) end |