pio 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c327a8b9d5983e25574403cbe3f1e5ddfad54633
4
- data.tar.gz: 1c8395383b9ceaebbda9cfa5cf3a1e1201f4aab4
3
+ metadata.gz: 27d53b285f5a1953f25ee64f1e4d2049433826f1
4
+ data.tar.gz: 63407621a578d12c4142b556c881921dc28d553c
5
5
  SHA512:
6
- metadata.gz: efa2dd373e70c0e235b0c004da7b839df4d98031d1ebfebe5c96972f8933bcdcd9b3c70d6a475cb8eabedad9b62a23116905fb2ac68c971b8e7af46435c472d8
7
- data.tar.gz: 046bf9ac402f5a9cd2ba411efcacff61857c68836b02c02563cb9125fd09f9dbd551deb1e6d69042a691ed0828289cf5f9ededbb9caa920a9a612cdefc24cb25
6
+ metadata.gz: 800d67d4ad15c762008ec915ff559a6d3c93d6908bd41d7f9a26cfbc7d11b4c90ca7eb0a15db68e772d6d05fc69e77185b895a28bcd249ebdf588fe06e42e0b0
7
+ data.tar.gz: 9cad26ff854970d9b0bbb55bfbb254335300eedb621a43436c4ae64b6b38e8ebba7a07d1d0c7fbf862dc8d02b8f39ece68605045bd3310bc699ed11906ea3476
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11.1 (1/15/2015)
4
+
5
+ ### New features
6
+ * [#116](https://github.com/trema/pio/issues/116): Support Cisco-style MAC addresses.
7
+
8
+
3
9
  ## 0.11.0 (1/15/2015)
4
10
 
5
11
  ### New features
@@ -32,7 +32,7 @@ module Pio
32
32
  fail TypeError
33
33
  end
34
34
  rescue ArgumentError, TypeError
35
- raise InvalidValueError, "Invalid MAC address: #{ value.inspect }"
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? { | each | each == 0xff }
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
- octet_regex = '[0-9a-fA-F][0-9a-fA-F]'
200
- if /^(#{ octet_regex }:){5}(#{ octet_regex })$/ =~ mac
201
- mac.gsub(':', '').hex
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
@@ -8,14 +8,7 @@ module Pio
8
8
  array :octets, type: :uint8, initial_length: 6
9
9
 
10
10
  def set(value)
11
- case value
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
@@ -1,5 +1,5 @@
1
1
  # Base module.
2
2
  module Pio
3
3
  # gem version.
4
- VERSION = '0.11.0'.freeze
4
+ VERSION = '0.11.1'.freeze
5
5
  end
@@ -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.0
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.2.2
586
+ rubygems_version: 2.4.5
587
587
  signing_key:
588
588
  specification_version: 4
589
589
  summary: Packet parser and generator.