iparith 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/iparith.gemspec +16 -0
- data/lib/iparith/parse.rb +33 -0
- data/lib/iparith.rb +14 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3761d3001222d5592a54018d056ea86729cfb8ceec3ca25db533ce21092123da
|
4
|
+
data.tar.gz: ed031810b77bbd2ba3dcd6296953971e5f6d048b38bc1453a1874c7bf39ef72a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f71038b507ebdf2f4ea4fe6cd19adac1523098c1251b59c4e62020fd05b4aaf6075548078f1440385d093611ca976f4b48aed5824d3ba6faa7e50cb381b434ec
|
7
|
+
data.tar.gz: f28336e8721276954ee156e399eff790d14dda788255d57a227f18da4015ff274f009aac762ae4d791981aa05e18790c201d4c2fdff0446ec1a7efdcd133825b
|
data/iparith.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'iparith'
|
3
|
+
spec.version = '0.0.2'
|
4
|
+
spec.authors = ['Forgot-His-Name']
|
5
|
+
spec.email = ['103605633+Forgot-His-Name@users.noreply.github.com']
|
6
|
+
|
7
|
+
spec.summary = 'Yet Another IP Calculator'
|
8
|
+
spec.description = 'IP manipulations, based on ipaddr gem'
|
9
|
+
spec.homepage = 'https://github.com/Forgot-His-Name/iparith'
|
10
|
+
spec.license = "BSD-3-Clause"
|
11
|
+
|
12
|
+
spec.files = ['iparith.gemspec', 'lib/iparith.rb', 'lib/iparith/parse.rb']
|
13
|
+
spec.require_paths = ['lib']
|
14
|
+
|
15
|
+
spec.add_runtime_dependency 'ipaddr', '~> 1.2'
|
16
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module IPArith
|
2
|
+
|
3
|
+
def self.macstr_valid?(macstr)
|
4
|
+
return nil unless macstr.is_a? String
|
5
|
+
|
6
|
+
rg_raw = /\A([a-f0-9]{12})\z/
|
7
|
+
mdata = rg_raw.match(macstr)
|
8
|
+
|
9
|
+
mdata ? true : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parse_macstr(mac_str)
|
13
|
+
return nil unless mac_str.is_a? String
|
14
|
+
|
15
|
+
cleaned_str = mac_str.downcase
|
16
|
+
cleaned_str.gsub!(/[-:.]/, '')
|
17
|
+
cleaned_str.gsub!('с', 'c') # replace russian c
|
18
|
+
|
19
|
+
rg_raw = /\A([a-f0-9]{12})\z/
|
20
|
+
mdata = rg_raw.match(cleaned_str)
|
21
|
+
return mdata[1] if mdata
|
22
|
+
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.ipstr_valid?(ipstr)
|
27
|
+
::IPAddr.new ipstr
|
28
|
+
true
|
29
|
+
rescue ::IPAddr::InvalidAddressError, ::IPAddr::AddressFamilyError
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/iparith.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'ipaddr'
|
2
|
+
require_relative 'iparith/check'
|
3
|
+
require_relative 'iparith/parse'
|
4
|
+
|
5
|
+
module IPArith
|
6
|
+
|
7
|
+
def self.addr_to_int(str)
|
8
|
+
addr = ::IPAddr.new str
|
9
|
+
addr.to_i
|
10
|
+
rescue ::IPAddr::InvalidAddressError, ::IPAddr::AddressFamilyError
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iparith
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Forgot-His-Name
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ipaddr
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
description: IP manipulations, based on ipaddr gem
|
28
|
+
email:
|
29
|
+
- 103605633+Forgot-His-Name@users.noreply.github.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- iparith.gemspec
|
35
|
+
- lib/iparith.rb
|
36
|
+
- lib/iparith/parse.rb
|
37
|
+
homepage: https://github.com/Forgot-His-Name/iparith
|
38
|
+
licenses:
|
39
|
+
- BSD-3-Clause
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.3.7
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Yet Another IP Calculator
|
60
|
+
test_files: []
|