utility 0.1.2 → 0.1.3
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/README.md +44 -6
- data/lib/utility/{atob.rb → base64.rb} +1 -1
- data/lib/utility/computer.rb +31 -0
- data/lib/utility/digest.rb +11 -0
- data/lib/utility/hmac.rb +9 -0
- data/lib/utility/url.rb +12 -0
- data/lib/utility/version.rb +1 -1
- data/lib/utility.rb +6 -3
- data/utility.gemspec +3 -2
- metadata +23 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d2ce37f67cff412377ef436b8cf7a930622a844
|
4
|
+
data.tar.gz: e325ade3a0e62e6c220fac485fdd32ac0d70dde5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e53b0dfae235814a63256647838f14ecf73e7b782cae2283b22a37b3fb4b90bb3b3ffac459b4a236ae9e8f2aa27d7ca0335f39111ffeedca323f79e945a161c2
|
7
|
+
data.tar.gz: 65b139f0818e279778355ebe3e6d6dd825bf49f1c2ce3ab498226f9f074ee27256c5ee4a09e2c47207724ea96eb86266f65180445af53047c9acec1f6b41d2d9
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## Utility ##
|
2
2
|
|
3
|
-
|
3
|
+
A number of ruby useful utilities.
|
4
4
|
|
5
5
|
|
6
6
|
### Installation ###
|
@@ -30,11 +30,49 @@ Utility.base64decode "dXRpbGl0eQ==" #=> utility
|
|
30
30
|
Utility.base64decode "5Lit5paH" #=> 中文
|
31
31
|
```
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
#### md5/rmd/sha ####
|
34
|
+
```ruby
|
35
|
+
Utility.md5 "ruby" #=> "58e53d1324eef6265fdb97b08ed9aadf"
|
36
|
+
Utility.rmd160 "ruby" #=> "29d9b710bc50866fa2399c3061cd02c0c8ffa197"
|
37
|
+
Utility.sha1 "ruby" #=> "18e40e1401eef67e1ae69efab09afb71f87ffb81"
|
38
|
+
Utility.sha256 "ruby" #=> "b9138194ffe9e7c8bb6d79d1ed56259553d18d9cb60b66e3ba5aa2e5b078055a"
|
39
|
+
Utility.sha384 "ruby" #=> "635365ef93ebf2c7a4e40b0b497da727ab8c2914eb9f052e6be40476f95d3daf44786790f5f0e843fab419b43022e069"
|
40
|
+
Utility.sha512 "ruby" #=> "423408d7723a3d80baefa804bd50b61a89667efec1713386a7b8efe28e5d13968307a908778cad210d7aa2dfe7db9a2aa86895f9fc1eeefcc99814310b207a6b"
|
41
|
+
```
|
42
|
+
|
43
|
+
#### hmc ####
|
44
|
+
```ruby
|
45
|
+
Utility.hmac "sha1", "key", "the data" #=> "ac5b94c09a6033e3aca1a02116ebf48722b155e0"
|
46
|
+
Utility.hmac "sha256", "key", "the data" #=> "00644ab9e7ce1b772c5fcd9b460b1a4fa78de4a55c162590ac506f2f76d62a40"
|
47
|
+
```
|
48
|
+
|
49
|
+
#### params parse ####
|
50
|
+
```ruby
|
51
|
+
# full url
|
52
|
+
Utility.parse_query "http://example.com/?param1=value1¶m2=value2¶m3=value3"
|
53
|
+
#=> {"param1"=>["value1"], "param2"=>["value2"], "param3"=>["value3"]}
|
54
|
+
|
55
|
+
# only query params
|
56
|
+
Utility.parse_query "param1=value1¶m2=value2¶m3=value3"
|
57
|
+
#=> {"param1"=>["value1"], "param2"=>["value2"], "param3"=>["value3"]}
|
58
|
+
```
|
59
|
+
### computer info ###
|
60
|
+
```ruby
|
61
|
+
# get hostname
|
62
|
+
Utility.get_hostname #=> "Charles"
|
63
|
+
|
64
|
+
# get ip address
|
65
|
+
Utility.get_ip #=> "192.168.12.26"
|
66
|
+
|
67
|
+
#get mac address
|
68
|
+
Utility.get_mac #=> "c8:60:00:10:ec:ee"
|
69
|
+
|
70
|
+
#get os
|
71
|
+
Utility.get_os #=> "linux"
|
72
|
+
|
73
|
+
#get os arch
|
74
|
+
Utility.get_arch #=> 64
|
75
|
+
```
|
38
76
|
|
39
77
|
### License ###
|
40
78
|
Released under the [MIT](http://opensource.org/licenses/MIT) license. See LICENSE file for details.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'macaddr'
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
module Utility::Computer
|
6
|
+
def get_ip
|
7
|
+
ip = Socket.ip_address_list.detect do |intf|
|
8
|
+
intf.ipv4? &&
|
9
|
+
!intf.ipv4_loopback? &&
|
10
|
+
!intf.ipv4_multicast? &&
|
11
|
+
!intf.ipv4_private?
|
12
|
+
end
|
13
|
+
ip.nil?? "IP address not found" : ip.ip_address
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_mac
|
17
|
+
Mac.addr.list rescue Mac.address
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_hostname
|
21
|
+
Socket.gethostname
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_os
|
25
|
+
Gem::Platform.local.os
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_arch
|
29
|
+
1226.size * 8
|
30
|
+
end
|
31
|
+
end
|
data/lib/utility/hmac.rb
ADDED
data/lib/utility/url.rb
ADDED
data/lib/utility/version.rb
CHANGED
data/lib/utility.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
|
2
|
-
require_relative "utility/atob"
|
1
|
+
Dir[File.dirname(__FILE__) + '/utility/*.rb'].each {|file| require file }
|
3
2
|
|
4
3
|
module Utility
|
5
|
-
extend
|
4
|
+
extend Base64
|
5
|
+
extend Digest
|
6
|
+
extend HMAC
|
7
|
+
extend URL
|
8
|
+
extend Computer
|
6
9
|
end
|
data/utility.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Cenxky"]
|
10
10
|
spec.email = ["cenxky@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.description = %q{
|
12
|
+
spec.summary = %q{A number of ruby useful utilities.}
|
13
|
+
spec.description = %q{A number of ruby useful utilities.}
|
14
14
|
spec.homepage = "https://github.com/cenxky/utility"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
+
spec.add_dependency "macaddr", "~> 1.0"
|
24
25
|
spec.add_development_dependency "bundler", "~> 1.14"
|
25
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cenxky
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: macaddr
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +66,7 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.0'
|
55
|
-
description:
|
69
|
+
description: A number of ruby useful utilities.
|
56
70
|
email:
|
57
71
|
- cenxky@gmail.com
|
58
72
|
executables: []
|
@@ -69,7 +83,11 @@ files:
|
|
69
83
|
- bin/console
|
70
84
|
- bin/setup
|
71
85
|
- lib/utility.rb
|
72
|
-
- lib/utility/
|
86
|
+
- lib/utility/base64.rb
|
87
|
+
- lib/utility/computer.rb
|
88
|
+
- lib/utility/digest.rb
|
89
|
+
- lib/utility/hmac.rb
|
90
|
+
- lib/utility/url.rb
|
73
91
|
- lib/utility/version.rb
|
74
92
|
- utility.gemspec
|
75
93
|
homepage: https://github.com/cenxky/utility
|
@@ -95,5 +113,5 @@ rubyforge_project:
|
|
95
113
|
rubygems_version: 2.6.6
|
96
114
|
signing_key:
|
97
115
|
specification_version: 4
|
98
|
-
summary:
|
116
|
+
summary: A number of ruby useful utilities.
|
99
117
|
test_files: []
|