xml2json-rb 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +1 -1
- data/ext/xml2json/Cargo.toml +1 -1
- data/ext/xml2json/src/lib.rs +33 -6
- data/lib/xml2json/version.rb +1 -1
- data/lib/xml2json/xml2json.so +0 -0
- data/lib/xml2json.rb +2 -0
- data/sig/xml2_json/json.rbs +1 -0
- data/sig/xml2_json/xml.rbs +1 -0
- metadata +8 -105
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7300901db2b5b148d589efdc043ba16afe065c4848300ae4fe13606e372c9e8f
|
4
|
+
data.tar.gz: bcfa9f9a7017c4d5c62f538b1abe07bd4c996d8a650e412798d43e7c18871e15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2719f4a3cc080a3b26c1c2e4e06fb351af1f6a71d882f2a192171a55b63caf66c4d2b143744239ea6842ef6cecfa00b4d0b45065660264d012dd281f716efe9b
|
7
|
+
data.tar.gz: 973a6c931eba9a847bcb48be1834e6c63a5c6f64538d199380b7405e4ca64d3ad316a4041490db7bf59623e24f299335ee68697f9ea304ab9f245b490eff1029
|
data/Cargo.lock
CHANGED
data/ext/xml2json/Cargo.toml
CHANGED
data/ext/xml2json/src/lib.rs
CHANGED
@@ -21,6 +21,14 @@ fn map_xml2json_err(error: xml2json_rs::X2JError) -> Error {
|
|
21
21
|
}
|
22
22
|
|
23
23
|
fn build_xml(args: &[Value]) -> Result<String, Error> {
|
24
|
+
build_xml_impl(args, false)
|
25
|
+
}
|
26
|
+
|
27
|
+
fn build_pretty_xml(args: &[Value]) -> Result<String, Error> {
|
28
|
+
build_xml_impl(args, true)
|
29
|
+
}
|
30
|
+
|
31
|
+
fn build_xml_impl(args: &[Value], build_pretty: bool) -> Result<String, Error> {
|
24
32
|
let args = scan_args::<_, _, (), (), _, ()>(args)?;
|
25
33
|
let (json_s, ): (String, ) = args.required;
|
26
34
|
let (opts, ): (Option<magnus::RHash>, ) = args.optional;
|
@@ -75,18 +83,18 @@ fn build_xml(args: &[Value]) -> Result<String, Error> {
|
|
75
83
|
if indent_char.is_some() {
|
76
84
|
indent_char_val = u8::try_from(indent_char.unwrap()).map_err(|error| Error::new(magnus::exception::type_error(), error.to_string()))?;
|
77
85
|
} else { indent_char_val = b' '; }
|
78
|
-
|
79
|
-
let intent = Indentation::new(
|
86
|
+
config.rendering(Indentation::new(
|
80
87
|
indent_char_val,
|
81
88
|
indent_size.unwrap_or(2),
|
82
|
-
);
|
83
|
-
|
84
|
-
} else if indent.unwrap_or(false) {
|
89
|
+
));
|
90
|
+
} else if indent.unwrap_or(build_pretty) {
|
85
91
|
// because Indentation::default is not the same as not calling config.rendering at all;
|
86
92
|
config.rendering(Indentation::default());
|
87
93
|
}
|
88
94
|
}
|
89
95
|
xml_builder = config.finalize();
|
96
|
+
} else if build_pretty {
|
97
|
+
xml_builder = XmlConfig::new().rendering(Indentation::default()).finalize();
|
90
98
|
} else { xml_builder = XmlBuilder::default(); }
|
91
99
|
|
92
100
|
xml_builder.build_from_json_string(&json_s).or_else(|error| {
|
@@ -95,6 +103,14 @@ fn build_xml(args: &[Value]) -> Result<String, Error> {
|
|
95
103
|
}
|
96
104
|
|
97
105
|
fn build_json(args: &[Value]) -> Result<String, Error> {
|
106
|
+
build_json_impl(args, false)
|
107
|
+
}
|
108
|
+
|
109
|
+
fn build_pretty_json(args: &[Value]) -> Result<String, Error> {
|
110
|
+
build_json_impl(args, true)
|
111
|
+
}
|
112
|
+
|
113
|
+
fn build_json_impl(args: &[Value], mut build_pretty: bool) -> Result<String, Error> {
|
98
114
|
// https://docs.rs/magnus/latest/magnus/scan_args/fn.scan_args.html
|
99
115
|
let args = scan_args::<_, _, (), (), _, ()>(args)?;
|
100
116
|
let (xml, ): (String, ) = args.required;
|
@@ -173,9 +189,18 @@ fn build_json(args: &[Value]) -> Result<String, Error> {
|
|
173
189
|
set_arg!(config, opts_hash, explicit_array, bool);
|
174
190
|
set_arg!(config, opts_hash, explicit_charkey, bool);
|
175
191
|
json_builder = config.finalize();
|
192
|
+
|
193
|
+
let indent = opts_hash.lookup::<_, Option<bool>>(magnus::Symbol::new("indent"))?;
|
194
|
+
if indent.is_some() {
|
195
|
+
build_pretty = indent.unwrap();
|
196
|
+
}
|
176
197
|
} else { json_builder = JsonBuilder::default(); }
|
177
198
|
|
178
|
-
|
199
|
+
if build_pretty {
|
200
|
+
json_builder.build_pretty_string_from_xml(&xml)
|
201
|
+
} else {
|
202
|
+
json_builder.build_string_from_xml(&xml)
|
203
|
+
}.or_else(|error| {
|
179
204
|
Err(map_xml2json_err(error))
|
180
205
|
})
|
181
206
|
}
|
@@ -192,7 +217,9 @@ fn init() -> Result<(), Error> {
|
|
192
217
|
let xml_encoding = xml.define_module("Encoding")?;
|
193
218
|
xml_encoding.const_set("UTF8", Encoding::UTF8.to_string())?;
|
194
219
|
xml.define_singleton_method("build", function!(build_xml, -1))?;
|
220
|
+
xml.define_singleton_method("build_pretty", function!(build_pretty_xml, -1))?;
|
195
221
|
let json = module.define_module("Json")?;
|
196
222
|
json.define_singleton_method("build", function!(build_json, -1))?;
|
223
|
+
json.define_singleton_method("build_pretty", function!(build_pretty_json, -1))?;
|
197
224
|
Ok(())
|
198
225
|
}
|
data/lib/xml2json/version.rb
CHANGED
data/lib/xml2json/xml2json.so
CHANGED
Binary file
|
data/lib/xml2json.rb
CHANGED
@@ -21,6 +21,7 @@ module Xml2Json
|
|
21
21
|
# # @return [String] XML string
|
22
22
|
# # @raise [RuntimeError] if the input string is invalid
|
23
23
|
# def self.build(json_s, opts: nil); end
|
24
|
+
# def self.build_pretty(json_s, opts: nil); end
|
24
25
|
# end
|
25
26
|
#
|
26
27
|
# module Json
|
@@ -30,5 +31,6 @@ module Xml2Json
|
|
30
31
|
# # @return [String] JSON string
|
31
32
|
# # @raise [RuntimeError] if the input string is invalid
|
32
33
|
# def self.build(xml, opts: nil); end
|
34
|
+
# def self.build_pretty(xml, opts: nil); end
|
33
35
|
# end
|
34
36
|
end
|
data/sig/xml2_json/json.rbs
CHANGED
data/sig/xml2_json/xml.rbs
CHANGED
metadata
CHANGED
@@ -1,113 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml2json-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- uvlad7
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: yard-rustdoc
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: pry
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: pry-byebug
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: yard
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rack
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rackup
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: puma
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
11
|
+
date: 2023-10-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
111
13
|
description: This gem helps to convert xml strings to json and vise versa
|
112
14
|
email:
|
113
15
|
- uvlad7@gmail.com
|
@@ -136,8 +38,9 @@ metadata:
|
|
136
38
|
homepage_uri: https://github.com/uvlad7/xml2json-rb
|
137
39
|
source_code_uri: https://github.com/uvlad7/xml2json-rb
|
138
40
|
changelog_uri: https://github.com/uvlad7/xml2json-rb/blob/main/CHANGELOG.md
|
139
|
-
documentation_uri: https://rubydoc.info/gems/xml2json-rb/0.
|
140
|
-
|
41
|
+
documentation_uri: https://rubydoc.info/gems/xml2json-rb/0.3.0
|
42
|
+
rubygems_mfa_required: 'true'
|
43
|
+
post_install_message:
|
141
44
|
rdoc_options: []
|
142
45
|
require_paths:
|
143
46
|
- lib
|
@@ -153,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
56
|
version: 3.3.11
|
154
57
|
requirements: []
|
155
58
|
rubygems_version: 3.4.10
|
156
|
-
signing_key:
|
59
|
+
signing_key:
|
157
60
|
specification_version: 4
|
158
61
|
summary: Ruby wrapper for xml2json-rs
|
159
62
|
test_files: []
|