pio 0.11.0 → 0.11.1
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/pio/mac.rb +7 -5
- data/lib/pio/type/mac_address.rb +1 -8
- data/lib/pio/version.rb +1 -1
- data/spec/pio/mac_spec.rb +75 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27d53b285f5a1953f25ee64f1e4d2049433826f1
|
4
|
+
data.tar.gz: 63407621a578d12c4142b556c881921dc28d553c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 800d67d4ad15c762008ec915ff559a6d3c93d6908bd41d7f9a26cfbc7d11b4c90ca7eb0a15db68e772d6d05fc69e77185b895a28bcd249ebdf588fe06e42e0b0
|
7
|
+
data.tar.gz: 9cad26ff854970d9b0bbb55bfbb254335300eedb621a43436c4ae64b6b38e8ebba7a07d1d0c7fbf862dc8d02b8f39ece68605045bd3310bc699ed11906ea3476
|
data/CHANGELOG.md
CHANGED
data/lib/pio/mac.rb
CHANGED
@@ -32,7 +32,7 @@ module Pio
|
|
32
32
|
fail TypeError
|
33
33
|
end
|
34
34
|
rescue ArgumentError, TypeError
|
35
|
-
raise InvalidValueError, "Invalid MAC address: #{
|
35
|
+
raise InvalidValueError, "Invalid MAC address: #{value.inspect}"
|
36
36
|
end
|
37
37
|
|
38
38
|
# @!group Converters
|
@@ -113,7 +113,7 @@ module Pio
|
|
113
113
|
# Mac.new("ff:ff:ff:ff:ff:ff").broadcast? #=> true
|
114
114
|
#
|
115
115
|
def broadcast?
|
116
|
-
to_a.all? { |
|
116
|
+
to_a.all? { |each| each == 0xff }
|
117
117
|
end
|
118
118
|
|
119
119
|
#
|
@@ -196,9 +196,11 @@ module Pio
|
|
196
196
|
private
|
197
197
|
|
198
198
|
def parse_mac_string(mac)
|
199
|
-
|
200
|
-
|
201
|
-
|
199
|
+
octet = '[0-9a-fA-F][0-9a-fA-F]'
|
200
|
+
doctet = octet * 2
|
201
|
+
case mac
|
202
|
+
when /^(?:#{octet}(:)){5}#{octet}$/, /^(?:#{doctet}(\.)){2}#{doctet}$/
|
203
|
+
mac.gsub(Regexp.last_match[1], '').hex
|
202
204
|
else
|
203
205
|
fail ArgumentError
|
204
206
|
end
|
data/lib/pio/type/mac_address.rb
CHANGED
@@ -8,14 +8,7 @@ module Pio
|
|
8
8
|
array :octets, type: :uint8, initial_length: 6
|
9
9
|
|
10
10
|
def set(value)
|
11
|
-
|
12
|
-
when String
|
13
|
-
self.octets = value.split(':').map { |each| ('0x' + each).hex }
|
14
|
-
when Integer
|
15
|
-
self.octets = (0..5).map { |each| value >> ((5 - each) * 8) & 0xff }
|
16
|
-
else
|
17
|
-
self.octets = value.to_a
|
18
|
-
end
|
11
|
+
self.octets = Mac.new(value).to_a
|
19
12
|
end
|
20
13
|
|
21
14
|
def get
|
data/lib/pio/version.rb
CHANGED
data/spec/pio/mac_spec.rb
CHANGED
@@ -46,6 +46,81 @@ describe Pio::Mac do
|
|
46
46
|
subject { super().to_s }
|
47
47
|
it { is_expected.to eq '11:22:33:44:55:66' }
|
48
48
|
end
|
49
|
+
|
50
|
+
describe '#to_str' do
|
51
|
+
context 'when "MAC = " + subject' do
|
52
|
+
it { expect('MAC = ' + subject).to eq 'MAC = 11:22:33:44:55:66' }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#multicast?' do
|
57
|
+
subject { super().multicast? }
|
58
|
+
it { is_expected.to be_truthy }
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#broadcast?' do
|
62
|
+
subject { super().broadcast? }
|
63
|
+
it { is_expected.to be_falsey }
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#reserved?' do
|
67
|
+
subject { super().reserved? }
|
68
|
+
it { is_expected.to be_falsey }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'with "1122.3344.5566" (Cisco style)' do
|
73
|
+
let(:value) { '1122.3344.5566' }
|
74
|
+
|
75
|
+
describe '#==' do
|
76
|
+
it { is_expected.to eq Pio::Mac.new('1122.3344.5566') }
|
77
|
+
it { is_expected.to eq Pio::Mac.new('11:22:33:44:55:66') }
|
78
|
+
it { is_expected.to eq '1122.3344.5566' }
|
79
|
+
it { is_expected.to eq '11:22:33:44:55:66' }
|
80
|
+
it { is_expected.not_to eq Pio::Mac.new('6655.4433.2211') }
|
81
|
+
it { is_expected.not_to eq Pio::Mac.new('66:55:44:33:22:11') }
|
82
|
+
it { is_expected.not_to eq '6655.4433.2211' }
|
83
|
+
it { is_expected.not_to eq '66:55:44:33:22:11' }
|
84
|
+
it { is_expected.to eq 0x112233445566 }
|
85
|
+
it { is_expected.not_to eq 42 }
|
86
|
+
it { is_expected.not_to eq 'INVALID_MAC_ADDRESS' }
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#eql?' do
|
90
|
+
it { expect(subject).to eql Pio::Mac.new('1122.3344.5566') }
|
91
|
+
it { expect(subject).to eql Pio::Mac.new('11:22:33:44:55:66') }
|
92
|
+
it { expect(subject).to eql '1122.3344.5566' }
|
93
|
+
it { expect(subject).to eql '11:22:33:44:55:66' }
|
94
|
+
it { expect(subject).not_to eql Pio::Mac.new('6655.4433.2211') }
|
95
|
+
it { expect(subject).not_to eql Pio::Mac.new('66:55:44:33:22:11') }
|
96
|
+
it { expect(subject).not_to eql '6655.4433.2211' }
|
97
|
+
it { expect(subject).not_to eql '66:55:44:33:22:11' }
|
98
|
+
it { expect(subject).to eql 0x112233445566 }
|
99
|
+
it { expect(subject).not_to eql 42 }
|
100
|
+
it { expect(subject).not_to eql 'INVALID_MAC_ADDRESS' }
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '#hash' do
|
104
|
+
subject { super().hash }
|
105
|
+
it { is_expected.to eq Pio::Mac.new('1122.3344.5566').hash }
|
106
|
+
it { is_expected.to eq Pio::Mac.new('11:22:33:44:55:66').hash }
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#to_i' do
|
110
|
+
subject { super().to_i }
|
111
|
+
it { is_expected.to eq 0x112233445566 }
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#to_a' do
|
115
|
+
subject { super().to_a }
|
116
|
+
it { is_expected.to eq [0x11, 0x22, 0x33, 0x44, 0x55, 0x66] }
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#to_s' do
|
120
|
+
subject { super().to_s }
|
121
|
+
it { is_expected.to eq '11:22:33:44:55:66' }
|
122
|
+
end
|
123
|
+
|
49
124
|
describe '#to_str' do
|
50
125
|
context 'when "MAC = " + subject' do
|
51
126
|
it { expect('MAC = ' + subject).to eq 'MAC = 11:22:33:44:55:66' }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yasuhito Takamiya
|
@@ -583,7 +583,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
583
583
|
version: '0'
|
584
584
|
requirements: []
|
585
585
|
rubyforge_project:
|
586
|
-
rubygems_version: 2.
|
586
|
+
rubygems_version: 2.4.5
|
587
587
|
signing_key:
|
588
588
|
specification_version: 4
|
589
589
|
summary: Packet parser and generator.
|