nkrb 0.1.0 → 0.1.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 +4 -4
- data/README.md +93 -2
- data/lib/nkrb/version.rb +1 -1
- data/lib/nkrb.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 931cc07da94ea186158913042f728c13ef1aa7a8
|
|
4
|
+
data.tar.gz: 30f93e8148d56cea77bd93532e2b1dba4720ce0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2a3f66383a7ba0bfdd7dcd5e0c2f4c700cd360da68b3c8aa2a4e1f8bd771ef91cf3e0ad62f54e40bf3d0a88a201a0655a64997e06dc92d944ca4ca04d517a2f6
|
|
7
|
+
data.tar.gz: 7580fd6398bd01f1a52c98d0d72c8c307c72dd410dc9944df3ad09301c89449a40a5f420f17d3639fc3cfcd35267e2e22fc6c15369b1c1dbe40a2ba89715a791
|
data/README.md
CHANGED
|
@@ -17,9 +17,100 @@ Or install it yourself as:
|
|
|
17
17
|
|
|
18
18
|
$ gem install nkrb
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Methods
|
|
21
|
+
#### 1. read_file
|
|
22
|
+
```
|
|
23
|
+
filename = "./text.txt"
|
|
24
|
+
texts = Nkrb.read_file(filename)
|
|
25
|
+
p texts
|
|
26
|
+
|
|
27
|
+
## =>
|
|
28
|
+
## [
|
|
29
|
+
## 'Hello world',
|
|
30
|
+
## "I'm your father."
|
|
31
|
+
## ]
|
|
32
|
+
```
|
|
33
|
+
test.txt
|
|
34
|
+
```
|
|
35
|
+
Hello world.
|
|
36
|
+
I'm your father.
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### 2. read_tsv
|
|
40
|
+
```
|
|
41
|
+
filename = "./data.tsv"
|
|
42
|
+
data = Nkrb.read_tsv(filename)
|
|
43
|
+
p data
|
|
44
|
+
|
|
45
|
+
## =>
|
|
46
|
+
## [
|
|
47
|
+
## {"id": "1", "name": "satoh"},
|
|
48
|
+
## {"id": "2", "name": "suzuki"},
|
|
49
|
+
## {"id": "3", "name": "takahashi"},
|
|
50
|
+
## ]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
data.tsv
|
|
54
|
+
```
|
|
55
|
+
id\tname
|
|
56
|
+
1\tsatoh
|
|
57
|
+
2\tsuzuki
|
|
58
|
+
3\ttakahashi
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### 3. pluck
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
collection = [
|
|
65
|
+
{"id": "1", "name": "satoh"},
|
|
66
|
+
{"id": "2", "name": "suzuki"},
|
|
67
|
+
{"id": "3", "name": "takahashi"},
|
|
68
|
+
]
|
|
69
|
+
p Nkrb.pluck(collection, key: "name")
|
|
70
|
+
## =>
|
|
71
|
+
## [
|
|
72
|
+
## "satoh", "suzuki", "takahashi"
|
|
73
|
+
## ]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### 4. download_image
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
image_url = "https://cdn.pixabay.com/photo/2017/05/15/17/43/calm-2315559_960_720.jpg"
|
|
80
|
+
dist_dir = "/tmp/"
|
|
81
|
+
filename = "nkrb_test_img"
|
|
82
|
+
Nkrb.download_image(image_url, dist_dir, filename)
|
|
83
|
+
|
|
84
|
+
## ls /tmp/nkrb_test_img.jpg
|
|
85
|
+
## => /tmp/nkrb_test_img.jpg
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
#### 5. faraday_connection
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
url = "http://sushi.com"
|
|
93
|
+
connection = Nkrb.faraday_connection(url)
|
|
94
|
+
res = connection.get do |req|
|
|
95
|
+
req.url 'search', :page => 2
|
|
96
|
+
req.params['limit'] = 100
|
|
97
|
+
end
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### 6. nokogiri
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
url = "https://www.youtube.com/?hl=ja&gl=JP"
|
|
104
|
+
Nkrb.nokogiri(url)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
#### 7. random_str
|
|
109
|
+
```
|
|
110
|
+
p Nkrb.random_str(10)
|
|
111
|
+
# => "2vjAkcdB34"
|
|
112
|
+
```
|
|
21
113
|
|
|
22
|
-
TODO: Write usage instructions here
|
|
23
114
|
|
|
24
115
|
## Development
|
|
25
116
|
|
data/lib/nkrb/version.rb
CHANGED
data/lib/nkrb.rb
CHANGED
|
@@ -128,4 +128,10 @@ module Nkrb
|
|
|
128
128
|
def nokogiri(url, charset='utf-8')
|
|
129
129
|
Nokogiri::HTML.parse(open(url), nil, charset)
|
|
130
130
|
end
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def random_str(len=5)
|
|
134
|
+
o = [('a'..'z'), ('A'..'Z'), ('0'..'9')].map { |i| i.to_a }.flatten
|
|
135
|
+
(0...len).map { o[rand(o.length)] }.join
|
|
136
|
+
end
|
|
131
137
|
end
|