mac_address 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed9afdc456dfe90492951a7edc7efb38dda3a1dd
4
+ data.tar.gz: 18c9ca4fdf6d449a2485b2fe2b93dad91f7869bf
5
+ SHA512:
6
+ metadata.gz: 25154e72e85748b14767f32e879f029fdbf4aa3c0de3fd251e636b93a2241541d8ab281f4a260730161637f0642acd6acf9a9ea00330f522454e50fde8bd8bef
7
+ data.tar.gz: 6f3a62d61e0b7bd00a13b92e4647fb9a44b7453158ace546f879634eba2e0843cd74cb7a2678221b7abdeb5c04b743d2e78325e5675fe24771b5782eb2c9dc9e
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 uceem
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ mac_address
2
+ ===========
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'MacAddress'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,37 @@
1
+ require 'str_quote'
2
+ require 'mac_address/version'
3
+
4
+ class MacAddress
5
+ def initialize(str)
6
+ @mac_str = str.strip.dequote.strip
7
+ n = @mac_str.index(':')
8
+ if not n.nil? and n >= 12
9
+ @mac_str = @mac_str.split(':')[0]
10
+ end
11
+ @mac_str = @mac_str.downcase.gsub(/^0[xX]/,'').gsub(/[^0-9a-f]/,'')
12
+
13
+ raise ArgumentError.new("Invalid MAC address: #{str}") if @mac_str.length != 12
14
+ end
15
+ def to_s
16
+ @mac_str
17
+ end
18
+ def to_i
19
+ @mac_str.hex
20
+ end
21
+ end
22
+
23
+ class String
24
+ def to_mac
25
+ MacAddress.new(self).to_s
26
+ end
27
+
28
+ def valid_mac?
29
+ begin
30
+ MacAddress.new(self).to_s
31
+ rescue ArgumentError => e
32
+ return false
33
+ end
34
+
35
+ true
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ class MacAddress
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'test/unit'
2
+ require 'mac_address'
3
+
4
+ class MacAddressTest < Test::Unit::TestCase
5
+ def test_truth
6
+ assert_kind_of Module, MacAddress
7
+ end
8
+
9
+ def test_mac
10
+ assert_equal 'aabbccddeeff', 'AA-BB-CC-DD-EE-FF:hello world'.to_mac
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mac_address
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Doug Wiegley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: str_quote
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Parse, validate, convert mac addresses, and String methods
28
+ email:
29
+ - doug@uceem.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/mac_address/version.rb
35
+ - lib/mac_address.rb
36
+ - Rakefile
37
+ - README.md
38
+ - LICENSE
39
+ - test/mac_address_test.rb
40
+ homepage: https://github.com/uceem/mac_address
41
+ licenses: []
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.0.6
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Mac address manipulation
63
+ test_files:
64
+ - test/mac_address_test.rb