Class: Synthra::Types::AddressLocation::Latitude

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

Overview

Latitude type

Instance Method Summary collapse

Instance Method Details

#generate_edge(rng, context, args) ⇒ Object



308
309
310
# File 'lib/synthra/types/address_location/locations.rb', line 308

def generate_edge(rng, context, args)
  [-90.0, 90.0, 0.0].sample(random: rng.instance_variable_get(:@random))
end

#generate_invalid(rng, context, args) ⇒ Object



312
313
314
# File 'lib/synthra/types/address_location/locations.rb', line 312

def generate_invalid(rng, context, args)
  [nil, "not a number", [], {}].sample(random: rng.instance_variable_get(:@random))
end

#generate_random(rng, context, args) ⇒ Float

Generate random latitude

Parameters:

Options Hash (args):

  • :range (Range)

    latitude range (default: -90..90)

  • :precision (Integer)

    decimal precision (default: 6)

Returns:

  • (Float)

    generated latitude



297
298
299
300
301
302
303
304
305
306
# File 'lib/synthra/types/address_location/locations.rb', line 297

def generate_random(rng, context, args)
  range = args[:range] || (-90.0..90.0)
  precision = args[:precision] || 6

  min = [range.min, -90.0].max
  max = [range.max, 90.0].min

  value = rng.rand * (max - min) + min
  value.round(precision)
end