fe_core_ext 0.30.0 → 0.30.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/lib/fe_core_ext/core_ext/array.rb +41 -40
- data/lib/fe_core_ext/core_ext/csv.rb +0 -7
- data/lib/fe_core_ext/core_ext/date.rb +55 -50
- data/lib/fe_core_ext/core_ext/hash.rb +8 -7
- data/lib/fe_core_ext/core_ext/integer.rb +7 -6
- data/lib/fe_core_ext/core_ext/numeric.rb +7 -6
- data/lib/fe_core_ext/core_ext/pathname.rb +44 -39
- data/lib/fe_core_ext/core_ext/string.rb +102 -101
- data/lib/fe_core_ext/core_ext/time.rb +12 -11
- data/lib/fe_core_ext/core_ext/uri.rb +5 -6
- data/lib/fe_core_ext/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8418dd8035fa99643b26a7960e1f3cf1e16bb0e4605aa64bf8febb14aaf36eda
|
4
|
+
data.tar.gz: ea17906cfd926562a7c39b2ec7460e91b4d232649923389fc7480b3652a151de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3122f6848091b0fe21a382273895705bfc8ccdf6cf71419fdb487924985e502b87959f6144449d285fae9b98de1b8ff73e130aa731e040f921f3b48a341c82fa
|
7
|
+
data.tar.gz: d82eecef2cd089d5c93e40f2d6bfbda73fa99d2e6ed21b1033d36bc732b964da5d6e0376729e1c0fa70f5929fda16cbdcfffabc2dcf232aadd90aa235c0af734
|
@@ -3,46 +3,47 @@
|
|
3
3
|
require "bigdecimal"
|
4
4
|
require "bigdecimal/util"
|
5
5
|
|
6
|
-
module FeCoreExt
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
6
|
+
module FeCoreExt
|
7
|
+
module CoreExt
|
8
|
+
module Array
|
9
|
+
def median
|
10
|
+
return if empty?
|
11
|
+
sorted = sort
|
12
|
+
len = sorted.length
|
13
|
+
(sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0
|
14
|
+
end
|
15
|
+
|
16
|
+
def mean
|
17
|
+
return if empty?
|
18
|
+
sum.to_d / size
|
19
|
+
end
|
20
|
+
|
21
|
+
# remove, remove_at, remove_if はこちらのものを使わせてもらっています。
|
22
|
+
# https://gist.github.com/nekoTheShadow/2de8a324f445bdde8a67
|
23
|
+
def remove(val)
|
24
|
+
# ブロックが渡されており、かつvalと等しい要素が見つからなかった場合
|
25
|
+
return yield if block_given? && !include?(val)
|
26
|
+
|
27
|
+
temp = dup
|
28
|
+
temp.delete(val)
|
29
|
+
temp
|
30
|
+
end
|
31
|
+
|
32
|
+
def remove_at(pos)
|
33
|
+
temp = dup
|
34
|
+
temp.delete_at(pos)
|
35
|
+
temp
|
36
|
+
end
|
37
|
+
|
38
|
+
def remove_if
|
39
|
+
temp = dup
|
40
|
+
# ブロックを持たない場合
|
41
|
+
return temp.delete_if unless block_given?
|
42
|
+
|
43
|
+
each { |val| temp.delete(val) if yield(val) }
|
44
|
+
temp
|
45
|
+
end
|
46
|
+
end
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
@@ -4,14 +4,7 @@ require "bigdecimal"
|
|
4
4
|
require "bigdecimal/util"
|
5
5
|
require "csv"
|
6
6
|
|
7
|
-
module FeCoreExt::CoreExt
|
8
|
-
end
|
9
|
-
|
10
|
-
module FeCoreExt::CoreExt::CSV
|
11
|
-
end
|
12
|
-
|
13
7
|
class CSV
|
14
|
-
#include FeCoreExt::CoreExt::CSV
|
15
8
|
Converters[:decimal] = lambda do |field|
|
16
9
|
begin
|
17
10
|
Float(field)
|
@@ -3,69 +3,74 @@
|
|
3
3
|
require "active_support"
|
4
4
|
require "active_support/time"
|
5
5
|
|
6
|
-
module FeCoreExt
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
6
|
+
module FeCoreExt
|
7
|
+
module CoreExt
|
8
|
+
module Date
|
9
|
+
def end_of_month?
|
10
|
+
self == end_of_month
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def range(duration)
|
14
|
+
Range.new(*[self + duration, self].minmax)
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def to_time_range
|
18
|
+
Range.new(beginning_of_day, end_of_day)
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
def nth_weekday(nth, weekday)
|
22
|
+
first_day = Date.new(year, month, 1)
|
23
|
+
weekdays_hash = { sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6 }
|
24
|
+
weekday_dates = (first_day..first_day.end_of_month).select { |d| d.wday == weekdays_hash[weekday] }
|
25
|
+
weekday_dates[nth - 1]
|
26
|
+
end
|
27
|
+
end
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
module FeCoreExt
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
module FeCoreExt
|
32
|
+
module CoreExt
|
33
|
+
module DateClassMethods
|
34
|
+
def parsable?(string)
|
35
|
+
parsed_hash = _parse(string)
|
36
|
+
return true if parsed_hash.has_key?(:year) && parsed_hash.has_key?(:mon)
|
34
37
|
|
35
|
-
|
36
|
-
|
38
|
+
false
|
39
|
+
end
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
def parse_as_future(string)
|
42
|
+
date = parse(string)
|
43
|
+
date > current ? date : date + 1.year
|
44
|
+
end
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
def parse_heisei(string)
|
47
|
+
string.match('平成(\d+)年(\d+)月(\d+)日') do
|
48
|
+
Date.new(::Regexp.last_match(1).to_i + 1988, ::Regexp.last_match(2).to_i, ::Regexp.last_match(3).to_i)
|
49
|
+
end
|
50
|
+
end
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
def parse_reiwa(string)
|
53
|
+
string.match('令和(\S+)年(\d+)月(\d+)日') do
|
54
|
+
year = 1 if ::Regexp.last_match(1) == "元"
|
55
|
+
year ||= ::Regexp.last_match(1).to_i
|
56
|
+
Date.new(year + 2018, ::Regexp.last_match(2).to_i, ::Regexp.last_match(3).to_i)
|
57
|
+
end
|
58
|
+
end
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
def parse_gengo(string)
|
61
|
+
parse_heisei(string) || parse_reiwa(string)
|
62
|
+
end
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
def parse_nengappi(string)
|
65
|
+
string.match(/(\d{4})年(\d+)月(\d+)日/) do
|
66
|
+
Date.new(::Regexp.last_match(1).to_i, ::Regexp.last_match(2).to_i, ::Regexp.last_match(3).to_i)
|
67
|
+
end
|
68
|
+
end
|
66
69
|
|
67
|
-
|
68
|
-
|
70
|
+
def parse_ja(string)
|
71
|
+
parse_nengappi(string) || parse_gengo(string)
|
72
|
+
end
|
73
|
+
end
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
@@ -3,13 +3,14 @@
|
|
3
3
|
require "active_support"
|
4
4
|
require "active_support/core_ext/hash"
|
5
5
|
|
6
|
-
module FeCoreExt
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
module FeCoreExt
|
7
|
+
module CoreExt
|
8
|
+
module Hash
|
9
|
+
def rename_key(original_key, new_key)
|
10
|
+
self[new_key] = delete(original_key) if key?(original_key)
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -4,57 +4,62 @@ require "pathname"
|
|
4
4
|
require "yaml"
|
5
5
|
require "fileutils"
|
6
6
|
|
7
|
-
module FeCoreExt
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
7
|
+
module FeCoreExt
|
8
|
+
module CoreExt
|
9
|
+
module Pathname
|
10
|
+
def load_yaml
|
11
|
+
return unless exist?
|
12
|
+
YAML.load_file(self)
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def glob(pattern, &block)
|
16
|
+
Pathname.glob(join(pattern), &block)
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def existence
|
20
|
+
self if exist?
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
def touch(options = {})
|
24
|
+
FileUtils.touch(@path, options)
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def rm(options = {})
|
28
|
+
FileUtils.rm(self, options)
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
def mkdir_p
|
32
|
+
mkpath
|
33
|
+
self
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def copy(dest)
|
37
|
+
FileUtils.cp(self, dest)
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
40
|
+
def require_relative
|
41
|
+
Kernel.require_relative(self)
|
42
|
+
end
|
43
|
+
end
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
|
-
module FeCoreExt
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
module FeCoreExt
|
48
|
+
module CoreExt
|
49
|
+
module PathnameClassMethods
|
50
|
+
def join(*args)
|
51
|
+
new(File.join(*args))
|
52
|
+
end
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
def mktmpdir(prefix_suffix = nil, tmpdir = nil)
|
55
|
+
if block_given?
|
56
|
+
Dir.mktmpdir prefix_suffix, tmpdir do |dir|
|
57
|
+
yield new(dir)
|
58
|
+
end
|
59
|
+
else
|
60
|
+
new(Dir.mktmpdir(prefix_suffix, tmpdir))
|
61
|
+
end
|
55
62
|
end
|
56
|
-
else
|
57
|
-
new(Dir.mktmpdir(prefix_suffix, tmpdir))
|
58
63
|
end
|
59
64
|
end
|
60
65
|
end
|
@@ -5,107 +5,108 @@ require "bigdecimal/util"
|
|
5
5
|
require "pathname"
|
6
6
|
require "nkf"
|
7
7
|
|
8
|
-
module FeCoreExt
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
8
|
+
module FeCoreExt
|
9
|
+
module CoreExt
|
10
|
+
module String
|
11
|
+
def to_integer
|
12
|
+
return unless valid_number?
|
13
|
+
delete(",").to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
def integer?
|
17
|
+
self.to_integer.to_s == self.delete(",")
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_decimal
|
21
|
+
return unless valid_number?
|
22
|
+
delete(",").to_d
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_decimal_new
|
26
|
+
return unless valid_number?
|
27
|
+
delete(",").to_d
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_float
|
31
|
+
return unless valid_number?
|
32
|
+
delete(",").to_f
|
33
|
+
end
|
34
|
+
|
35
|
+
def valid_sec_code?
|
36
|
+
valid_chars = "[0-9ACDFGHJKLMNPRSTUWXY]"
|
37
|
+
match?(/^\d#{valid_chars}\d#{valid_chars}$/)
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_pathname
|
41
|
+
Pathname(self)
|
42
|
+
end
|
43
|
+
|
44
|
+
def not_number?
|
45
|
+
to_i == 0 && match("0").nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
def valid_number?
|
49
|
+
match?(/^-?([0-9][\d,.]*)$/)
|
50
|
+
end
|
51
|
+
|
52
|
+
## deprecated
|
53
|
+
def zen_to_han
|
54
|
+
tr("0-9A-Za-z &・-()", '0-9A-Za-z &・\-()')
|
55
|
+
end
|
56
|
+
|
57
|
+
def alphanumeric_zen_to_han
|
58
|
+
tr("0-9A-Za-z &・.-()", '0-9A-Za-z &・.\-()')
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_katakana
|
62
|
+
tr("ぁ-ん", "ァ-ン")
|
63
|
+
end
|
64
|
+
|
65
|
+
def match?(str)
|
66
|
+
/#{str}/ === self
|
67
|
+
end
|
68
|
+
|
69
|
+
def kana_upcase
|
70
|
+
tr("ァィゥェォヵヶッャュョヮ", "アイウエオカケツヤユヨワ")
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_han_kana
|
74
|
+
return if self.nil?
|
75
|
+
NKF.nkf("-wxZ4", self)
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_zen_kana
|
79
|
+
return if self.nil?
|
80
|
+
NKF.nkf("-wX", self)
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_date_in_ja
|
84
|
+
to_date_in_ja_seireki || to_date_in_ja_heisei
|
85
|
+
end
|
86
|
+
|
87
|
+
def to_date_in_ja_seireki
|
88
|
+
match(/(\d{4})年(\d{1,2})月(\d{1,2})日/) { Date.new($1.to_i, $2.to_i, $3.to_i) }
|
89
|
+
end
|
90
|
+
|
91
|
+
def to_date_in_ja_heisei
|
92
|
+
match(/平成(\d{2})年(\d{1,2})月(\d{1,2})日/) { Date.new($1.to_i + 1988, $2.to_i, $3.to_i) }
|
93
|
+
end
|
94
|
+
|
95
|
+
# remove also no break space and other space like characters.
|
96
|
+
def strong_strip
|
97
|
+
reverse.gsub(/^\p{Zs}+|^\p{Cf}+/, "").reverse.gsub(/^\p{Zs}+|^\p{Cf}+/, "")
|
98
|
+
end
|
99
|
+
|
100
|
+
def sjis_encodable
|
101
|
+
tr("\u301C\u2212\u00A2\u00A3\u00AC\u2014\u2016",
|
102
|
+
"\uFF5E\uFF0D\uFFE0\uFFE1\uFFE2\u2015\u2225")
|
103
|
+
end
|
104
|
+
|
105
|
+
def eucjp_encodable
|
106
|
+
tr("\uFF5E\uFF0D\uFFE0\uFFE1\uFFE2\u2015\u2225",
|
107
|
+
"\u301C\u2212\u00A2\u00A3\u00AC\u2014\u2016")
|
108
|
+
end
|
109
|
+
end
|
109
110
|
end
|
110
111
|
end
|
111
112
|
|
@@ -3,16 +3,17 @@
|
|
3
3
|
require "active_support"
|
4
4
|
require "active_support/time"
|
5
5
|
|
6
|
-
module FeCoreExt
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
module FeCoreExt
|
7
|
+
module CoreExt
|
8
|
+
module Time
|
9
|
+
def floor(unit = :sec)
|
10
|
+
case unit
|
11
|
+
when :sec
|
12
|
+
Time.zone.local(year, month, day, hour, min, sec)
|
13
|
+
else
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -23,4 +24,4 @@ end
|
|
23
24
|
class Time
|
24
25
|
include FeCoreExt::CoreExt::Time
|
25
26
|
extend FeCoreExt::CoreExt::TimeClassMethods
|
26
|
-
end
|
27
|
+
end
|
@@ -5,9 +5,6 @@ require "fileutils"
|
|
5
5
|
require "open-uri"
|
6
6
|
require "net/http"
|
7
7
|
|
8
|
-
module FeCoreExt::CoreExt
|
9
|
-
end
|
10
|
-
|
11
8
|
module URI
|
12
9
|
def download(file)
|
13
10
|
warn "URI#downloadの引数にはPathnameを使いましょう!" if file.is_a?(String)
|
@@ -27,8 +24,10 @@ module URI
|
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
module URI
|
28
|
+
class Generic
|
29
|
+
def basename
|
30
|
+
::File.basename(path)
|
31
|
+
end
|
33
32
|
end
|
34
33
|
end
|
data/lib/fe_core_ext/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fe_core_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.30.
|
4
|
+
version: 0.30.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tetsu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|