maca 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aee82516c71df181d561ed67d5aab2fbaf266c1e23b463692584e9920bc495a1
4
- data.tar.gz: d2374172b04b9ea1f198e94b40872a3d98e4ac1a07219d08c86f642f83f19c1f
3
+ metadata.gz: 85373f80878aa63bce4ea371c64c5f3c41ad318f76b2eb72733d2c72b57794bf
4
+ data.tar.gz: fc31705f45c8209c33da8d9b8d5effb211c417b2fdf6ccbaf3330fdd5e8d9d90
5
5
  SHA512:
6
- metadata.gz: 24b2d90e99227d6c1ce894f625932fd561605ec4a60983353869ded49e37ff13849e13702667ba986026bb1a2eaa099e15ba90a11ffb736de9228c14d0ad994a
7
- data.tar.gz: 6679b4d4f25160966aed55c642bdfd06cebf176dcdec020b1800e139e4809215bc6e5e098edc212823a6b3c90c23ce11651511d2233bd32c7c1e075ca32971d1
6
+ metadata.gz: d1bfca6661cba8b9b968f789003249d992db9c178970196611d7a40db12f87c88e8d2eabc9e9cc82882f280ad68e96b03ee8c92713b4ab06b354d620659ffacf
7
+ data.tar.gz: 54deb43cf21756b8d3e81d85557cfb9b6f95def0074edadcdea4f0f7b0c034648be1068eae84a9c8d18b44c1b008d2374f8f90f38b901eba2524da1ad12f4570
data/README.md CHANGED
@@ -77,6 +77,8 @@ Macaddress.new("00:00:00:00:00:00") == Macaddress.new("00:00:00:00:00:01")
77
77
 
78
78
  ### Address type check
79
79
 
80
+ Determine the type of a MAC address, such as whether it is unicast or multicast, and whether it is locally or universally administered.
81
+
80
82
  ```ruby
81
83
  Macaddress.new("00:00:00:00:00:00").unicast?
82
84
  => true
@@ -97,6 +99,20 @@ Macaddress.new("02:00:00:00:00:00").random?
97
99
  => true
98
100
  ```
99
101
 
102
+ ### OUI
103
+
104
+ Extract the Organizationally Unique Identifier (OUI) from a MAC address.
105
+
106
+ The `#oui` method returns the first 24 bits (or the first 3 octets) of a MAC Address, which typically identifies the device manufacturer or vendor.
107
+
108
+ ```ruby
109
+ Macaddress.new("01:23:45:67:89:ab").oui # default format: :base16
110
+ => "012345"
111
+
112
+ Macaddress.new("01:23:45:67:89:ab").oui(format: :hex)
113
+ => "01-23-45"
114
+ ```
115
+
100
116
  ## Development
101
117
 
102
118
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -5,7 +5,12 @@ module Maca
5
5
  DEFAULT_DELIMITER = ':'
6
6
  DEFAULT_STEP = 2
7
7
  DELIMITERS = ':.-'
8
- REGEXP_MACADDRESS = /^([0-9A-Fa-f]{2}[#{DELIMITERS}]?){5}([0-9A-Fa-f]{2})$/
8
+ REGEXP_LIST_MACADDRESS = [
9
+ /^([0-9A-Fa-f]{2}[#{DELIMITERS}]){5}([0-9A-Fa-f]{2})$/, # xx:xx:xx:xx:xx:xx
10
+ /^([0-9A-Fa-f]{4}[#{DELIMITERS}]){2}([0-9A-Fa-f]{4})$/, # xxxx:xxxx:xxxx
11
+ /^([0-9A-Fa-f]{6}[#{DELIMITERS}]){1}([0-9A-Fa-f]{6})$/, # xxxxxx:xxxxxx
12
+ /^([0-9A-Fa-f]{12})$/, # xxxxxxxxxxxx
13
+ ]
9
14
 
10
15
  def initialize(addr)
11
16
  if Maca::Macaddress.valid?(addr)
@@ -16,7 +21,13 @@ module Maca
16
21
  end
17
22
 
18
23
  def self.valid?(addr)
19
- REGEXP_MACADDRESS.match?(addr)
24
+ REGEXP_LIST_MACADDRESS.each do |regexp_macaddress|
25
+ if regexp_macaddress.match?(addr)
26
+ return true
27
+ end
28
+ end
29
+
30
+ false
20
31
  end
21
32
 
22
33
  def to_s
@@ -59,6 +70,19 @@ module Maca
59
70
  unicast? && locally_administered?
60
71
  end
61
72
 
73
+ def oui(format: :base16)
74
+ oui = @macaddress[0..5]
75
+
76
+ # format: base 16 (xxxxxx)
77
+ if format.to_s == "base16"
78
+ return oui.upcase
79
+ end
80
+
81
+ # default format: hex (xx-xx-xx)
82
+ delimiter = "-"
83
+ oui.upcase.scan(/.{1,2}/).join(delimiter)
84
+ end
85
+
62
86
  def ==(other)
63
87
  self.to_s == other.to_s
64
88
  end
data/lib/maca/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Maca
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taketo Takashima