Class: Synthra::Types::TechnologyInternet::Ip

Inherits:
Base
  • Object
show all
Defined in:
lib/synthra/types/technology_internet/networking.rb

Overview

Ip type

Instance Method Summary collapse

Instance Method Details

#generate_edge(rng, context, args) ⇒ Object



29
30
31
# File 'lib/synthra/types/technology_internet/networking.rb', line 29

def generate_edge(rng, context, args)
  ["0.0.0.0", "255.255.255.255", "127.0.0.1"].sample(random: rng.instance_variable_get(:@random))
end

#generate_invalid(rng, context, args) ⇒ Object



33
34
35
# File 'lib/synthra/types/technology_internet/networking.rb', line 33

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

#generate_random(rng, context, args) ⇒ String

Generate a random IPv4 address

Parameters:

Returns:

  • (String)

    IPv4 address string



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/synthra/types/technology_internet/networking.rb', line 15

def generate_random(rng, context, args)
  adapter = faker_adapter(context)
  if adapter
    adapter.ip_v4_address

  else
    Faker::Internet.ip_v4_address
  end

rescue StandardError
  "#{rng.int(1, 255)}.#{rng.int(0, 255)}.#{rng.int(0, 255)}.#{rng.int(1, 255)}"
end