utility 0.1.7 → 0.1.8
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 +34 -10
- data/lib/utility/url.rb +25 -0
- data/lib/utility/version.rb +1 -1
- data/utility.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c405ee382d7806115552f2126152760ac81caf31
|
4
|
+
data.tar.gz: 108299419e98711c7cc8e833bf31d3b69f2f8ecf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c8254c38159d0d53a71ca236249018c88bd31b36cd9bdb85076c37708edc696020d5830398a239f25130026f0b95dfb3f36ca2844ad1668fc2d0ac1ab401183
|
7
|
+
data.tar.gz: 3b9fa1484b6b3f3c257be312313e0e440690931ecf087f376efa933527216c259f0cdc35a2212c9cf50b860a0dfbd4bdd84f2deff8e30939a66309ac75249775
|
data/README.md
CHANGED
@@ -40,37 +40,61 @@ Utility.sha384 "ruby" #=> "635365ef93ebf2c7a4e40b0b497da727ab8c2914eb9f052e6be4
|
|
40
40
|
Utility.sha512 "ruby" #=> "423408d7723a3d80baefa804bd50b61a89667efec1713386a7b8efe28e5d13968307a908778cad210d7aa2dfe7db9a2aa86895f9fc1eeefcc99814310b207a6b"
|
41
41
|
```
|
42
42
|
|
43
|
-
####
|
43
|
+
#### hmac ####
|
44
44
|
```ruby
|
45
45
|
Utility.hmac "sha1", "key", "the data" #=> "ac5b94c09a6033e3aca1a02116ebf48722b155e0"
|
46
46
|
Utility.hmac "sha256", "key", "the data" #=> "00644ab9e7ce1b772c5fcd9b460b1a4fa78de4a55c162590ac506f2f76d62a40"
|
47
47
|
```
|
48
48
|
|
49
|
-
####
|
49
|
+
#### url/html ####
|
50
50
|
```ruby
|
51
|
-
#
|
51
|
+
# params parse
|
52
52
|
Utility.parse_query "http://example.com/?param1=value1¶m2=value2¶m3=value3"
|
53
53
|
#=> {"param1"=>["value1"], "param2"=>["value2"], "param3"=>["value3"]}
|
54
|
-
|
55
|
-
# only query params
|
56
54
|
Utility.parse_query "param1=value1¶m2=value2¶m3=value3"
|
57
55
|
#=> {"param1"=>["value1"], "param2"=>["value2"], "param3"=>["value3"]}
|
56
|
+
|
57
|
+
# url escape
|
58
|
+
Utility.url_escape "http://example.com/search?q=#ruby&from=深圳"
|
59
|
+
#=> "http://example.com/search?q=%23ruby&from=%E6%B7%B1%E5%9C%B3"
|
60
|
+
Utility.url_escape "http://example.com/search?q=#ruby&from=深圳", :all
|
61
|
+
#=> "http%3A%2F%2Fexample.com%2Fsearch%3Fq%3D%23ruby%26from%3D%E6%B7%B1%E5%9C%B3"
|
62
|
+
Utility.url_escape "深圳香港一水之隔"
|
63
|
+
#=> "%E6%B7%B1%E5%9C%B3%E9%A6%99%E6%B8%AF%E4%B8%80%E6%B0%B4%E4%B9%8B%E9%9A%94"
|
64
|
+
|
65
|
+
# url unescape
|
66
|
+
Utility.url_unescape "http://example.com/search?q=%23ruby&from=%E6%B7%B1%E5%9C%B3"
|
67
|
+
#=> "http://example.com/search?q=#ruby&from=深圳"
|
68
|
+
Utility.url_unescape "http%3A%2F%2Fexample.com%2Fsearch%3Fq%3D%23ruby%26from%3D%E6%B7%B1%E5%9C%B3"
|
69
|
+
#=> "http://example.com/search?q=#ruby&from=深圳"
|
70
|
+
Utility.url_unescape "%E6%B7%B1%E5%9C%B3%E9%A6%99%E6%B8%AF%E4%B8%80%E6%B0%B4%E4%B9%8B%E9%9A%94"
|
71
|
+
#=> "深圳香港一水之隔"
|
72
|
+
|
73
|
+
# html escape/unescape
|
74
|
+
Utility.html_escape "<p>some text</p>" #=> "<p>some text</p>"
|
75
|
+
Utility.html_unescape "<p>some text</p>" #=> "<p>some text</p>"
|
76
|
+
Utility.html_unescape "©2017" #=> "©2017"
|
77
|
+
|
78
|
+
# html text
|
79
|
+
Utility.html_text("<p>This <span>is</span> <p>plain</p> text</p>")
|
80
|
+
#=> "This is plain text"
|
58
81
|
```
|
82
|
+
|
59
83
|
#### computer info ####
|
60
84
|
```ruby
|
61
|
-
#
|
85
|
+
# hostname
|
62
86
|
Utility.get_hostname #=> "Charles"
|
63
87
|
|
64
|
-
#
|
88
|
+
# ip address
|
65
89
|
Utility.get_ip #=> "192.168.12.26"
|
66
90
|
|
67
|
-
#
|
91
|
+
# mac address
|
68
92
|
Utility.get_mac #=> "c8:60:00:10:ec:ee"
|
69
93
|
|
70
|
-
#
|
94
|
+
# os
|
71
95
|
Utility.get_os #=> "linux"
|
72
96
|
|
73
|
-
#
|
97
|
+
# os arch
|
74
98
|
Utility.get_arch #=> 64
|
75
99
|
```
|
76
100
|
|
data/lib/utility/url.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
require 'uri'
|
3
|
+
require 'nokogiri'
|
3
4
|
|
4
5
|
module Utility::URL
|
5
6
|
def parse_query(url)
|
@@ -9,4 +10,28 @@ module Utility::URL
|
|
9
10
|
CGI.parse url
|
10
11
|
end
|
11
12
|
end
|
13
|
+
|
14
|
+
def url_escape(url, all = :no)
|
15
|
+
if url =~ URI::regexp && all != :all
|
16
|
+
URI.escape url
|
17
|
+
else
|
18
|
+
CGI::escape url
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def url_unescape(url)
|
23
|
+
URI.unescape url
|
24
|
+
end
|
25
|
+
|
26
|
+
def html_escape(html)
|
27
|
+
CGI::escapeHTML(html).gsub(" ", " ")
|
28
|
+
end
|
29
|
+
|
30
|
+
def html_unescape(html)
|
31
|
+
Nokogiri::HTML.parse(html).text
|
32
|
+
end
|
33
|
+
|
34
|
+
def html_text(html)
|
35
|
+
Nokogiri::HTML(html).text
|
36
|
+
end
|
12
37
|
end
|
data/lib/utility/version.rb
CHANGED
data/utility.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.add_dependency "macaddr", "~> 1.0"
|
25
|
+
spec.add_dependency "nokogiri", "~> 1.8"
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.14"
|
26
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cenxky
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: macaddr
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|