Created
November 3, 2016 16:32
-
-
Save boxofrad/b1957b6ab3e6a4236d673980a64a99a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EthernetFrame | |
attr_reader :bytes | |
def initialize(bytes) | |
@bytes = bytes | |
end | |
def destination_mac | |
format_mac(bytes[0, 6]) | |
end | |
def source_mac | |
format_mac(bytes[6, 6]) | |
end | |
private | |
def format_mac(mac_bytes) | |
mac_bytes.map do |byte| | |
byte.to_s(16).rjust(2, '0') | |
end.join(':').upcase | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment