kaki-utils 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/lib/kaki/utils.rb +3 -0
- data/lib/kaki/utils/check_fname_overlapping.rb +21 -0
- data/lib/kaki/utils/imgsuffix.rb +1 -0
- data/lib/kaki/utils/rec_decimal.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15365e0061e2b715e3b4b10b4afca6afbbb9a53a
|
4
|
+
data.tar.gz: a4f5df6c961ebf0bc349b9ec96d7d40ac916561b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52fbab242215c3ddc75849f2410c03182f3d548c258cea618c77cebf1de3586cf32588a03c83fbf9272e4a1d263f65b72abd77eeda213fae6fab93a955589267
|
7
|
+
data.tar.gz: cba8d597754852dde3a77590c83dfaf09e14960366d53371d75c534abaeb440edb907055c6d3c1d85c4a5b91ae20b1ef85b4239b0851be23a60b1bd0bf93e2f9
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
##
|
1
|
+
## module Utils
|
2
2
|
|
3
3
|
```ruby
|
4
4
|
require "kaki/utils"
|
@@ -44,3 +44,12 @@ method
|
|
44
44
|
|
45
45
|
* Integer#times_retry(message: true, wait: 0)
|
46
46
|
|
47
|
+
## check overlapping of file names
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require "kaki/utils/check\_fname_overlapping"
|
51
|
+
```
|
52
|
+
method
|
53
|
+
|
54
|
+
* File.check\_fname\_overlapping(file_name)
|
55
|
+
|
data/lib/kaki/utils.rb
CHANGED
@@ -12,6 +12,7 @@ module Utils
|
|
12
12
|
|
13
13
|
|
14
14
|
#Web上のバイナリファイルの保存
|
15
|
+
# @return [Boolean]
|
15
16
|
def getfile(url, filename, max=0)
|
16
17
|
count = 0
|
17
18
|
begin
|
@@ -32,6 +33,7 @@ module Utils
|
|
32
33
|
|
33
34
|
|
34
35
|
#一文字入力
|
36
|
+
# @return [String]
|
35
37
|
def key_wait
|
36
38
|
c = nil
|
37
39
|
loop {break if (c = STDIN.getch)}
|
@@ -63,6 +65,7 @@ module Utils
|
|
63
65
|
|
64
66
|
|
65
67
|
#画像ファイルでなければ削除
|
68
|
+
# @return [Boolean]
|
66
69
|
def delete_non_img(fname)
|
67
70
|
if Utils.imgexist?(fname)
|
68
71
|
false
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class File
|
2
|
+
#ファイル名が重複していれば (1) などを付加して返す
|
3
|
+
# @return [String]
|
4
|
+
def self.check_fname_overlapping(fname)
|
5
|
+
return fname unless File.exist?(fname)
|
6
|
+
dir = File.dirname(fname)
|
7
|
+
base = File.basename(fname)
|
8
|
+
m = /(.+)(\..+)$/.match(base)
|
9
|
+
result, suffix = m ? [m[1], m[2]] : [base, ""]
|
10
|
+
|
11
|
+
begin
|
12
|
+
result = if (m1 = /(.+)\((\d+)\)$/.match(result))
|
13
|
+
m1[1] + "(#{m1[2].to_i + 1})"
|
14
|
+
else
|
15
|
+
result + "(1)"
|
16
|
+
end
|
17
|
+
end while File.exist?(r = File.join(dir, result + suffix))
|
18
|
+
r
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/lib/kaki/utils/imgsuffix.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
class Rational
|
2
2
|
#分数を循環小数に直す
|
3
|
+
# @return [String]
|
3
4
|
def to_rec_decimal
|
4
5
|
f, num = (self < 0) ? ["-", -self] : ["", self]
|
5
6
|
|
@@ -27,6 +28,7 @@ end
|
|
27
28
|
class String
|
28
29
|
alias :__to_r__ :to_r
|
29
30
|
#循環小数を分数に直す
|
31
|
+
# @return [Rational]
|
30
32
|
def to_r
|
31
33
|
st = delete(" ")
|
32
34
|
return st.__to_r__ unless (m = /^([^\d]?)(\d+)\.(\d*)\((\d+)\)$/.match(st))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaki-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- obelisk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gtk2
|
@@ -46,6 +46,7 @@ extra_rdoc_files: []
|
|
46
46
|
files:
|
47
47
|
- README.md
|
48
48
|
- lib/kaki/utils.rb
|
49
|
+
- lib/kaki/utils/check_fname_overlapping.rb
|
49
50
|
- lib/kaki/utils/imgsuffix.rb
|
50
51
|
- lib/kaki/utils/rec_decimal.rb
|
51
52
|
- lib/kaki/utils/retry.rb
|