canon 0.1.1 → 0.1.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 +4 -4
- data/.rubocop.yml +2 -2
- data/.rubocop_todo.yml +12 -23
- data/README.adoc +51 -1
- data/lib/canon/rspec_matchers.rb +5 -2
- data/lib/canon/version.rb +1 -1
- data/lib/canon.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcf999be5f47b3ee417e783de5b54be7efe27c8123d0b2becaa8263587d224e6
|
4
|
+
data.tar.gz: 86c5c3679003d3b6ff1c96674ba10b7dc5ca6e92b39200b3729170185b030c2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 592cb969e6c55b8b19081f19a412746409b01113bdb1ec638931638606a301d0de360fd25a227681068f3ffbece325b180a85ccc9b5087bebd0b22ee24d67677
|
7
|
+
data.tar.gz: 0e96447cef7283e641218d3be17511d5fb49fa1995013136af1b3c8281d90feada43bcd95316621af01e69b7a065f4dc1635701b0991668a15f72bbdfe81819e
|
data/.rubocop.yml
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
# See https://github.com/metanorma/cimas
|
3
3
|
inherit_from:
|
4
4
|
- .rubocop_todo.yml
|
5
|
-
- https://raw.githubusercontent.com/riboseinc/oss-guides/
|
5
|
+
- https://raw.githubusercontent.com/riboseinc/oss-guides/main/ci/rubocop.yml
|
6
6
|
|
7
7
|
# local repo-specific modifications
|
8
8
|
# ...
|
9
9
|
|
10
10
|
AllCops:
|
11
|
-
TargetRubyVersion:
|
11
|
+
TargetRubyVersion: 3.0
|
data/.rubocop_todo.yml
CHANGED
@@ -1,40 +1,29 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2025-
|
3
|
+
# on 2025-08-24 10:22:06 UTC using RuboCop version 1.79.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count: 2
|
10
|
-
# This cop supports safe autocorrection (--autocorrect).
|
11
|
-
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
12
|
-
# URISchemes: http, https
|
13
|
-
Layout/LineLength:
|
14
|
-
Exclude:
|
15
|
-
- 'canon.gemspec'
|
16
|
-
- 'spec/canon/xml/formatter_spec.rb'
|
17
|
-
|
18
9
|
# Offense count: 1
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
22
|
-
Style/TrailingCommaInArguments:
|
10
|
+
# Configuration parameters: Severity, Include.
|
11
|
+
# Include: **/*.gemspec
|
12
|
+
Gemspec/RequiredRubyVersion:
|
23
13
|
Exclude:
|
24
|
-
- '
|
14
|
+
- 'canon.gemspec'
|
25
15
|
|
26
16
|
# Offense count: 1
|
27
17
|
# This cop supports safe autocorrection (--autocorrect).
|
28
|
-
|
29
|
-
# SupportedStylesForMultiline: comma, consistent_comma, diff_comma, no_comma
|
30
|
-
Style/TrailingCommaInArrayLiteral:
|
18
|
+
Layout/EmptyLineAfterGuardClause:
|
31
19
|
Exclude:
|
32
20
|
- 'lib/canon/rspec_matchers.rb'
|
33
21
|
|
34
|
-
# Offense count:
|
22
|
+
# Offense count: 2
|
35
23
|
# This cop supports safe autocorrection (--autocorrect).
|
36
|
-
# Configuration parameters:
|
37
|
-
#
|
38
|
-
|
24
|
+
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
25
|
+
# URISchemes: http, https
|
26
|
+
Layout/LineLength:
|
39
27
|
Exclude:
|
40
|
-
- '
|
28
|
+
- 'canon.gemspec'
|
29
|
+
- 'spec/canon/xml/formatter_spec.rb'
|
data/README.adoc
CHANGED
@@ -67,6 +67,26 @@ The `format` method is used to pretty-print and canonicalize the input data,
|
|
67
67
|
with the arguments of the method taking the content and the format type as
|
68
68
|
arguments.
|
69
69
|
|
70
|
+
Syntax:
|
71
|
+
|
72
|
+
[source,ruby]
|
73
|
+
----
|
74
|
+
# Generic method
|
75
|
+
Canon.format({content}, {format})
|
76
|
+
|
77
|
+
# Format-specific method
|
78
|
+
Canon.format_{format}({content})
|
79
|
+
----
|
80
|
+
|
81
|
+
Where,
|
82
|
+
|
83
|
+
`{content}`:: is the input string
|
84
|
+
`{format}`:: is the format type, which can be `:xml`, `:yaml`, or `:json`.
|
85
|
+
|
86
|
+
|
87
|
+
.Demonstration of formatting methods
|
88
|
+
[example]
|
89
|
+
====
|
70
90
|
[source,ruby]
|
71
91
|
----
|
72
92
|
require 'canon'
|
@@ -75,17 +95,24 @@ require 'canon'
|
|
75
95
|
xml_input = '<root><b>2</b><a>1</a></root>'
|
76
96
|
formatted_xml = Canon.format(xml_input, :xml)
|
77
97
|
# => Pretty-printed XML with consistent formatting
|
98
|
+
# or
|
99
|
+
formatted_xml = Canon.format_xml(xml_input)
|
78
100
|
|
79
101
|
# YAML formatting
|
80
102
|
yaml_input = "---\nz: 3\na: 1\nb: 2\n"
|
81
103
|
formatted_yaml = Canon.format(yaml_input, :yaml)
|
82
104
|
# => YAML with keys sorted alphabetically
|
105
|
+
# or
|
106
|
+
formatted_yaml = Canon.format_yaml(yaml_input)
|
83
107
|
|
84
108
|
# JSON formatting
|
85
109
|
json_input = '{"z":3,"a":1,"b":2}'
|
86
110
|
formatted_json = Canon.format(json_input, :json)
|
87
111
|
# => Pretty-printed JSON with keys sorted alphabetically
|
112
|
+
# or
|
113
|
+
formatted_json = Canon.format_json(json_input)
|
88
114
|
----
|
115
|
+
====
|
89
116
|
|
90
117
|
|
91
118
|
=== Parsing
|
@@ -94,20 +121,44 @@ Canon can also parse XML, YAML, and JSON strings into Ruby objects. The `parse`
|
|
94
121
|
method takes the content and the format type as arguments, returning a Ruby
|
95
122
|
object (Hash, Array, etc.) for YAML and JSON, or a Nokogiri XML document for XML.
|
96
123
|
|
124
|
+
Syntax:
|
125
|
+
|
126
|
+
[source,ruby]
|
127
|
+
----
|
128
|
+
# Generic method
|
129
|
+
Canon.parse({content}, {format})
|
130
|
+
|
131
|
+
# Format-specific method
|
132
|
+
Canon.parse_{format}({content})
|
133
|
+
----
|
134
|
+
|
135
|
+
Where,
|
136
|
+
|
137
|
+
`{content}`:: is the input string
|
138
|
+
`{format}`:: is the format type, which can be `:xml`, `:yaml`, or `:json`.
|
139
|
+
|
140
|
+
.Demonstration of parsing methods
|
141
|
+
[example]
|
142
|
+
====
|
97
143
|
[source,ruby]
|
98
144
|
----
|
99
145
|
# Parse XML
|
100
146
|
xml_doc = Canon.parse(xml_input, :xml)
|
147
|
+
xml_doc = Canon.parse_xml(xml_input)
|
101
148
|
# => Nokogiri::XML::Document
|
102
149
|
|
103
150
|
# Parse YAML
|
104
151
|
yaml_obj = Canon.parse(yaml_input, :yaml)
|
152
|
+
yaml_obj = Canon.parse_yaml(yaml_input)
|
105
153
|
# => Ruby object (Hash, Array, etc.)
|
106
154
|
|
107
155
|
# Parse JSON
|
108
156
|
json_obj = Canon.parse(json_input, :json)
|
157
|
+
json_obj = Canon.parse_json(json_input)
|
109
158
|
# => Ruby object (Hash, Array, etc.)
|
110
159
|
----
|
160
|
+
====
|
161
|
+
|
111
162
|
|
112
163
|
=== RSpec matchers
|
113
164
|
|
@@ -166,4 +217,3 @@ https://github.com/lutaml/canon.
|
|
166
217
|
== Copyright and license
|
167
218
|
|
168
219
|
Copyright Ribose. https://opensource.org/licenses/BSD-2-Clause[BSD-2-Clause License].
|
169
|
-
|
data/lib/canon/rspec_matchers.rb
CHANGED
@@ -15,14 +15,17 @@ module Canon
|
|
15
15
|
class SerializationMatcher
|
16
16
|
def initialize(expected, format = :xml)
|
17
17
|
@expected = expected
|
18
|
+
unless SUPPORTED_FORMATS.include?(format.to_sym)
|
19
|
+
raise Canon::Error, "Unsupported format: #{format}"
|
20
|
+
end
|
21
|
+
|
18
22
|
@format = format.to_sym
|
19
23
|
@result = nil
|
20
24
|
end
|
21
25
|
|
22
26
|
def matches?(target)
|
23
27
|
@target = target
|
24
|
-
send("match_#{@format}")
|
25
|
-
raise(Canon::Error, "Unsupported format: #{@format}")
|
28
|
+
send("match_#{@format}")
|
26
29
|
rescue NoMethodError
|
27
30
|
raise Canon::Error, "Unsupported format: #{@format}"
|
28
31
|
end
|
data/lib/canon/version.rb
CHANGED
data/lib/canon.rb
CHANGED
@@ -8,6 +8,8 @@ require_relative "canon/formatters/json_formatter"
|
|
8
8
|
require_relative "canon/rspec_matchers" if defined?(::RSpec)
|
9
9
|
|
10
10
|
module Canon
|
11
|
+
SUPPORTED_FORMATS = %i[xml yaml json].freeze
|
12
|
+
|
11
13
|
# Format content based on the specified format type
|
12
14
|
# @param content [String] The content to format
|
13
15
|
# @param format [Symbol] The format type (:xml, :yaml, :json)
|
@@ -37,5 +39,17 @@ module Canon
|
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
42
|
+
# Define shorthand methods for each supported format
|
43
|
+
# Creates parse_{format} and format_{format} methods
|
44
|
+
SUPPORTED_FORMATS.each do |format|
|
45
|
+
define_singleton_method("parse_#{format}") do |content|
|
46
|
+
parse(content, format)
|
47
|
+
end
|
48
|
+
|
49
|
+
define_singleton_method("format_#{format}") do |content|
|
50
|
+
format(content, format)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
40
54
|
class Error < StandardError; end
|
41
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: compare-xml
|