json_data_extractor 0.0.14 → 0.0.16

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: 2a35a6bf0ed27b3f5a0ef9a13e96ff21ac28ff873772696aef65069821dbf23e
4
- data.tar.gz: 9dba998316601c445cebe5872f04e18c68575196b9ed52e4128f01b47139049a
3
+ metadata.gz: eb1e531fd36334345d1fdaf9668b1c03c0a65e8f954605c8d4071734d70f7153
4
+ data.tar.gz: ee96e0f43442b7c1f7a8ca9b43c61a98ebf4a7067b2fe4daf19d14d32aac4088
5
5
  SHA512:
6
- metadata.gz: 204620707292cb9e1f805db3bbc72b44e6dca7f1dc86dceefa8b9b1126f437fa70bc152af38bb502741d620884f141b46664a6a6c80fb135bc20f394b8d62300
7
- data.tar.gz: '0482bfd00032c8e07c0a97ce88c6bbfba824bc6ea7eb6ec7aecd329c92982afae2853333f096695d68f52f737a01cca253a9f199616a22e565211b60b9d0f6eb'
6
+ metadata.gz: 1e25722f1867eced86d8367f9202f83155363547448876b75ec10c3865f5e6360bbd329fbd3aee7e87cef123324b0b157405b8d36c1ec6af4662309f188d0d85
7
+ data.tar.gz: 59db96a9ce39007d3bc87bcf242efc07dcf0142f2d997f32c443e86552276abdc29c2c205630944e3023019f446371a041ad334cff92a951fccd3be0c1feeafd
data/README.md CHANGED
@@ -191,6 +191,8 @@ results = extractor.extract(schema)
191
191
 
192
192
  ```
193
193
 
194
+ You can also define any class that implements a `call` method and use it as a modifier.
195
+
194
196
  Modifiers are called in the order in which they are defined, so keep that in mind when defining your
195
197
  schema. By default JDE raises an ArgumentError if a modifier is not applicable, but this behaviour
196
198
  can be configured to ignore missing modifiers. See Configuration options for details
@@ -36,6 +36,12 @@ class JsonDataExtractor
36
36
  case mod
37
37
  when Symbol, Proc
38
38
  mod
39
+ when Class
40
+ if mod.respond_to?(:call)
41
+ mod
42
+ else
43
+ raise ArgumentError, "Modifier class must respond to call: #{mod.inspect}"
44
+ end
39
45
  when String
40
46
  mod.to_sym
41
47
  else
@@ -103,7 +109,7 @@ class JsonDataExtractor
103
109
  end
104
110
 
105
111
  def apply_single_modifier(modifier, value)
106
- if modifier.is_a?(Proc)
112
+ if modifier.respond_to?(:call) # Matches Proc, Lambda, Method, and callable objects
107
113
  modifier.call(value)
108
114
  elsif modifiers.key?(modifier)
109
115
  modifiers[modifier].call(value)
data/lib/src/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class JsonDataExtractor
2
- VERSION = '0.0.14'
2
+ VERSION = '0.0.16'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_data_extractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Buslaev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-07 00:00:00.000000000 Z
11
+ date: 2024-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,7 +122,7 @@ homepage: https://github.com/austerlitz/json_data_extractor
122
122
  licenses:
123
123
  - MIT
124
124
  metadata: {}
125
- post_install_message:
125
+ post_install_message:
126
126
  rdoc_options: []
127
127
  require_paths:
128
128
  - lib
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  requirements: []
140
140
  rubygems_version: 3.2.3
141
- signing_key:
141
+ signing_key:
142
142
  specification_version: 4
143
143
  summary: Transform JSON data structures with the help of a simple schema and JsonPath
144
144
  expressions. Use the JsonDataExtractor gem to extract and modify data from complex