fe_core_ext 0.30.0 → 0.30.1

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