Class: Synthra::Types::TechnologyInternet::MacAddress

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

Overview

MacAddress type

Instance Method Summary collapse

Instance Method Details

#generate_edge(rng, context, args) ⇒ Object



97
98
99
# File 'lib/synthra/types/technology_internet/networking.rb', line 97

def generate_edge(rng, context, args)
  ["00:00:00:00:00:00", "FF:FF:FF:FF:FF:FF"].sample(random: rng.instance_variable_get(:@random))
end

#generate_invalid(rng, context, args) ⇒ Object



101
102
103
# File 'lib/synthra/types/technology_internet/networking.rb', line 101

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

#generate_random(rng, context, args) ⇒ String

Generate random MAC address

Parameters:

Options Hash (args):

  • :format (Symbol)

    format type (:colon, :dash, :none)

Returns:

  • (String)

    generated MAC address



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/synthra/types/technology_internet/networking.rb', line 81

def generate_random(rng, context, args)
  format_type = args[:format] || :colon

  # Generate 6 octets (12 hex digits)
  octets = 6.times.map { format("%02X", rng.int(0, 255)) }

  case format_type
  when :dash
    octets.join("-")
  when :none
    octets.join
  else # :colon
    octets.join(":")
  end
end