funcml-core 0.9.0 → 0.9.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 229952b1c47eb4c17e0cc4209f1e0226306010425713c4d1ed9d1b6a4bd0adfb
4
- data.tar.gz: 7435707d489decc839bad4c3697c72534fdc7fa465b44049c9e52bd4a1899e47
3
+ metadata.gz: da9c2ae2356b8d3277cbbaecbeeed6592a285211d8cb77802cbe29aa6b60ef8b
4
+ data.tar.gz: de2322628fec13589866f907191aed5b50b7daf3c123e87d6b49ea61f4965750
5
5
  SHA512:
6
- metadata.gz: 68458c9df2ec863e3030c35b082405e39c71dba66576f33f5306f0046aedd674eae5720e491ad331880f7e89e04eded00e6fc9d77b51db6af86ea8f678a2be4d
7
- data.tar.gz: '08d321d32f188aad017170d3df8c8c42b45b3ad40939a3ec20294464679ecee0b8875bfde73f496ff7bac543fb6c536c1c327c24bcbeeebdfa92aa925525c6c2'
6
+ metadata.gz: 4b7ee27995128146f4678e98830a55683ed3989980d78ecbb1f11584913b669cb2d010c681266b4ad3dbc5edc28dad06e42cf8ce19f832f49b07564d11c4827a
7
+ data.tar.gz: 6b57b3bb725765618c42753ae33fabb25982ec92af880720cc4721271856a570161017e4ea93393324cd7319698a5ad786c77745427beb563b81c07e987540c2
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ require "json"
2
3
 
3
4
  class Hash
4
5
  def _string(mutations)
@@ -18,4 +19,20 @@ class Hash
18
19
  obj.mutate(mutations).to_f
19
20
  end
20
21
  end
22
+
23
+ def _json(mutations)
24
+ self.fetch(:_json).then do |obj|
25
+ obj.mutate(mutations).to_json
26
+ end
27
+ end
28
+
29
+ def _fromJson(mutations)
30
+ self.fetch(:_fromJson).then do |obj|
31
+ # usage of symbolize_names instead of deep_symbolize_keys as it is only
32
+ # implemented in funcml-cli.
33
+ JSON.parse(obj, symbolize_names: true).then do |struct|
34
+ struct.mutate(mutations)
35
+ end
36
+ end
37
+ end
21
38
  end
@@ -7,6 +7,15 @@ class Hash
7
7
  # dup is here to avoid iteration error on #delete/#merge
8
8
  self.dup.each do |key, value|
9
9
  case key
10
+ in /^\\_.*$/
11
+ # escapes keys starting with backslash (\).
12
+ # gsub is only implemented on String, not Symbol - this is why
13
+ # we cast the key to string before re-casting it to sym later.
14
+ escaped_key = key.to_s
15
+ .gsub('\\_', '_')
16
+
17
+ self[escaped_key.to_sym] = value.mutate(mutations)
18
+ self.delete(key)
10
19
  in /^_.*$/
11
20
  # recursive mutation of result from pattern-matched _method
12
21
  # once recursively mutated, we return the final object by guard
@@ -53,6 +62,12 @@ class Hash
53
62
  in {le: [first, second]}
54
63
  first.mutate(mutations) <= second.mutate(mutations)
55
64
 
65
+ in {match: [first, second]}
66
+ first.match?(Regexp.new(second))
67
+
68
+ in {unmatch: [first, second]}
69
+ !first.match?(Regexp.new(second))
70
+
56
71
  # or should evaluated by top-level if as true or false.
57
72
  in {or: or_conds}
58
73
  or_conds.any? do |cond|
@@ -154,6 +169,17 @@ class Hash
154
169
  end
155
170
  end
156
171
 
172
+ def _replace(mutations)
173
+ self.fetch(:_replace).then do |ctx|
174
+ content = ctx.fetch(:content)
175
+ ctx.fetch(:substitutions).each do |from, to|
176
+ content = content.gsub(from, to)
177
+ end
178
+
179
+ content
180
+ end
181
+ end
182
+
157
183
  def dig_from_str(path, mutations)
158
184
  path_array_sym = path.split('.').map do |sub|
159
185
  sub.to_sym
@@ -161,5 +187,4 @@ class Hash
161
187
 
162
188
  self.dig(*path_array_sym).mutate(mutations)
163
189
  end
164
-
165
190
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Funcml
4
- VERSION = "0.9.0"
4
+ VERSION = "0.9.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funcml-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mimopotato
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-14 00:00:00.000000000 Z
11
+ date: 2024-08-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A library that implements mutations on data-structures
14
14
  email:
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  requirements: []
65
- rubygems_version: 3.3.3
65
+ rubygems_version: 3.3.27
66
66
  signing_key:
67
67
  specification_version: 4
68
68
  summary: funcml-core