eac_ruby_utils 0.74.0 → 0.75.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_ruby_utils/compact.rb +22 -0
- data/lib/eac_ruby_utils/fs_cache.rb +1 -1
- data/lib/eac_ruby_utils/patches/object/compact.rb +20 -0
- data/lib/eac_ruby_utils/patches/string/delimited.rb +16 -0
- data/lib/eac_ruby_utils/string_delimited.rb +70 -0
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68abbc7acfbe86b2e24bb721047ef23e0d99c7444c9d97e107db9adbb92adca8
|
4
|
+
data.tar.gz: af3d13481855122ae753eaaf0ed1dec94ec620524d03cf358592573405017399
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0041989ecacd0b99a2a699fd2fbbceebf22f002360c8f4ef1b622bce4975d230e42b8912b4236d3d653b55a9864c00873be0222ac33ecf8b1efc588880c4bb23'
|
7
|
+
data.tar.gz: 0a030761ca0ae9030bd68421b8c6e1cbd883ffcae51e947241821deef8c887fcf99819ef2fc7c3f2912c962b81c7c35271950934c87553839923a492af698e8b
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class Compact
|
5
|
+
attr_reader :object, :attributes
|
6
|
+
|
7
|
+
def initialize(object, attributes)
|
8
|
+
@object = object
|
9
|
+
@attributes = attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Array]
|
13
|
+
def to_a
|
14
|
+
attributes.map { |attr| object.send(attr) }
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Hash]
|
18
|
+
def to_h
|
19
|
+
attributes.map { |attr| [attr.to_sym, object.send(attr)] }.to_h
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -6,7 +6,7 @@ require 'tmpdir'
|
|
6
6
|
module EacRubyUtils
|
7
7
|
class << self
|
8
8
|
def fs_cache
|
9
|
-
@fs_cache ||= ::EacRubyUtils::FilesystemCache.new(::Dir.tmpdir, '
|
9
|
+
@fs_cache ||= ::EacRubyUtils::FilesystemCache.new(::Dir.tmpdir, 'eac_ruby_utils_fs_cache')
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/compact'
|
4
|
+
|
5
|
+
class Object
|
6
|
+
# @return [EacRubyUtils::Compact]
|
7
|
+
def compact(*attributes)
|
8
|
+
::EacRubyUtils::Compact.new(self, attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Array]
|
12
|
+
def compact_to_a(*attributes)
|
13
|
+
compact(*attributes).to_a
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Hash]
|
17
|
+
def compact_to_h(*attributes)
|
18
|
+
compact(*attributes).to_h
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/string_delimited'
|
4
|
+
|
5
|
+
class String
|
6
|
+
# @return [EacRubyUtils::StringDelimited]
|
7
|
+
def delimited(begin_delimiter, end_delimiter)
|
8
|
+
::EacRubyUtils::StringDelimited.new(self, begin_delimiter, end_delimiter)
|
9
|
+
end
|
10
|
+
|
11
|
+
%w[inner outer without_inner without_outer].each do |method_suffix|
|
12
|
+
define_method "delimited_#{method_suffix}" do |begin_delimiter, end_delimiter|
|
13
|
+
delimited(begin_delimiter, end_delimiter).send(method_suffix)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class StringDelimited
|
5
|
+
attr_reader :string, :begin_delimiter, :end_delimiter
|
6
|
+
|
7
|
+
def initialize(string, begin_delimiter, end_delimiter)
|
8
|
+
@string = string
|
9
|
+
@begin_delimiter = begin_delimiter
|
10
|
+
@end_delimiter = end_delimiter
|
11
|
+
end
|
12
|
+
|
13
|
+
def inner
|
14
|
+
between_indexes(content_index, end_index).to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def outer
|
18
|
+
between_indexes(begin_index, after_end_index).to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def without_inner
|
22
|
+
without_join(
|
23
|
+
between_indexes(sos_index, content_index), between_indexes(end_index, eos_index)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def without_outer
|
28
|
+
without_join(
|
29
|
+
between_indexes(sos_index, begin_index),
|
30
|
+
between_indexes(after_end_index, eos_index)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def after_end_index
|
37
|
+
end_index.if_present { |v| v + end_delimiter.length }
|
38
|
+
end
|
39
|
+
|
40
|
+
def begin_index
|
41
|
+
string.index(begin_delimiter)
|
42
|
+
end
|
43
|
+
|
44
|
+
def between_indexes(a_begin_index, a_end_index)
|
45
|
+
a_begin_index && a_end_index ? string[a_begin_index, a_end_index - a_begin_index] : nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def content_index
|
49
|
+
begin_index.if_present { |v| v + begin_delimiter.length }
|
50
|
+
end
|
51
|
+
|
52
|
+
def without_join(*strings)
|
53
|
+
return string if strings.any?(&:nil?)
|
54
|
+
|
55
|
+
strings.join('')
|
56
|
+
end
|
57
|
+
|
58
|
+
def end_index
|
59
|
+
content_index.if_present { |_v| string.index(end_delimiter, content_index) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def sos_index
|
63
|
+
0
|
64
|
+
end
|
65
|
+
|
66
|
+
def eos_index
|
67
|
+
string.length
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_ruby_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.75.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/eac_ruby_utils/common_constructor/class_initialize.rb
|
107
107
|
- lib/eac_ruby_utils/common_constructor/instance_initialize.rb
|
108
108
|
- lib/eac_ruby_utils/common_constructor/super_args.rb
|
109
|
+
- lib/eac_ruby_utils/compact.rb
|
109
110
|
- lib/eac_ruby_utils/context.rb
|
110
111
|
- lib/eac_ruby_utils/contextualizable.rb
|
111
112
|
- lib/eac_ruby_utils/core_ext.rb
|
@@ -187,6 +188,7 @@ files:
|
|
187
188
|
- lib/eac_ruby_utils/patches/module/speaker.rb
|
188
189
|
- lib/eac_ruby_utils/patches/object.rb
|
189
190
|
- lib/eac_ruby_utils/patches/object/asserts.rb
|
191
|
+
- lib/eac_ruby_utils/patches/object/compact.rb
|
190
192
|
- lib/eac_ruby_utils/patches/object/debug.rb
|
191
193
|
- lib/eac_ruby_utils/patches/object/if_nil.rb
|
192
194
|
- lib/eac_ruby_utils/patches/object/if_present.rb
|
@@ -199,6 +201,7 @@ files:
|
|
199
201
|
- lib/eac_ruby_utils/patches/regexp/if_match.rb
|
200
202
|
- lib/eac_ruby_utils/patches/regexp/to_parser.rb
|
201
203
|
- lib/eac_ruby_utils/patches/string.rb
|
204
|
+
- lib/eac_ruby_utils/patches/string/delimited.rb
|
202
205
|
- lib/eac_ruby_utils/patches/string/inflector.rb
|
203
206
|
- lib/eac_ruby_utils/patches/time.rb
|
204
207
|
- lib/eac_ruby_utils/patches/time/required_zone.rb
|
@@ -219,6 +222,7 @@ files:
|
|
219
222
|
- lib/eac_ruby_utils/speaker.rb
|
220
223
|
- lib/eac_ruby_utils/speaker/receiver.rb
|
221
224
|
- lib/eac_ruby_utils/speaker/sender.rb
|
225
|
+
- lib/eac_ruby_utils/string_delimited.rb
|
222
226
|
- lib/eac_ruby_utils/struct.rb
|
223
227
|
- lib/eac_ruby_utils/version.rb
|
224
228
|
- lib/eac_ruby_utils/yaml.rb
|