Class: Synthra::Types::AddressLocation::Address

Inherits:
Base
  • Object
show all
Defined in:
lib/synthra/types/address_location/addresses.rb

Overview

Address type

Instance Method Summary collapse

Instance Method Details

#generate_edge(rng, context, args) ⇒ Object



38
39
40
# File 'lib/synthra/types/address_location/addresses.rb', line 38

def generate_edge(rng, context, args)
  ["", "123 Main St", "PO Box 123", "Apt 4B, 123 Main St"].sample(random: rng.instance_variable_get(:@random))
end

#generate_invalid(rng, context, args) ⇒ Object



42
43
44
# File 'lib/synthra/types/address_location/addresses.rb', line 42

def generate_invalid(rng, context, args)
  [nil, 123, [], {}, true].sample(random: rng.instance_variable_get(:@random))
end

#generate_random(rng, context, args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/synthra/types/address_location/addresses.rb', line 8

def generate_random(rng, context, args)
  include_country = args[:include_country] || false

  adapter = faker_adapter(context)
  if adapter
    if include_country
      adapter.full_address

    else
      "#{adapter.street_address}, #{adapter.city}, #{adapter.state_abbr} #{adapter.zip_code}"
    end

  else
    if include_country
      Faker::Address.full_address
    else
      "#{Faker::Address.street_address}, #{Faker::Address.city}, #{Faker::Address.state_abbr} #{Faker::Address.zip_code}"
    end

  end

rescue StandardError
  rng.sample([
    "123 Main St, New York, NY 10001",
    "456 Oak Avenue, Los Angeles, CA 90001",
    "789 Elm Street, Chicago, IL 60601"
  ])
end