canon 0.1.1 → 0.1.2

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: 4a8c9da045b6e04e129d80c19a1ff7a3437841c28b5e3036913259eb3dc9fc7d
4
- data.tar.gz: c0a871782a39c618ac5f947f748b6d2674f6c18c574d94a7526cdfc32bf58238
3
+ metadata.gz: 8731c16240a9a73c7596318b4ff10ba07041f5ad781b035e3cd09c4939e82cee
4
+ data.tar.gz: d78fa0d273ef2cad336cec103443b00c7ee41dcd0d5289a30059804b13e5fa43
5
5
  SHA512:
6
- metadata.gz: 7351aa91465f71a18cadb390b58fe9f39563822f9333f3d1e80a88538561c42518bb597873ac70d23ada797f39a3d9f2019e450cb498329aff4eeda32dd1c1a7
7
- data.tar.gz: 05fee78316eebc60ebe29c99c755933a4c96e3cb463dabbffa07929505eb400e5c7a1aeb8cbf608e01cbaeaa859e4c4864ee4a415ddd379136d47fc70090ccc4
6
+ metadata.gz: 5e5412a35878e93a86f678d836b723a3ae02f5adc4b5bd1be9b1f1dff4d8ed8f83c6838665ca7d20e8adf3adb1d502d4a97e0c09b4988082fdd20c3cc9c3988f
7
+ data.tar.gz: 477ddf5857421cc2eff7444faee2f9becd8afc1e759bed1de6c4e8e657f3a5b8a6e34b573b5f0b347ae401c93cb70d70479db3b0f51ea32f0d8b7a9da91ad460
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/master/ci/rubocop.yml
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: 2.7
11
+ TargetRubyVersion: 3.0
data/.rubocop_todo.yml CHANGED
@@ -1,11 +1,18 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2025-07-29 05:56:24 UTC using RuboCop version 1.79.0.
3
+ # on 2025-07-29 13:58:20 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: 1
10
+ # Configuration parameters: Severity, Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'canon.gemspec'
15
+
9
16
  # Offense count: 2
10
17
  # This cop supports safe autocorrection (--autocorrect).
11
18
  # Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
@@ -14,27 +21,3 @@ Layout/LineLength:
14
21
  Exclude:
15
22
  - 'canon.gemspec'
16
23
  - 'spec/canon/xml/formatter_spec.rb'
17
-
18
- # Offense count: 1
19
- # This cop supports safe autocorrection (--autocorrect).
20
- # Configuration parameters: EnforcedStyleForMultiline.
21
- # SupportedStylesForMultiline: comma, consistent_comma, no_comma
22
- Style/TrailingCommaInArguments:
23
- Exclude:
24
- - 'lib/canon/rspec_matchers.rb'
25
-
26
- # Offense count: 1
27
- # This cop supports safe autocorrection (--autocorrect).
28
- # Configuration parameters: EnforcedStyleForMultiline.
29
- # SupportedStylesForMultiline: comma, consistent_comma, diff_comma, no_comma
30
- Style/TrailingCommaInArrayLiteral:
31
- Exclude:
32
- - 'lib/canon/rspec_matchers.rb'
33
-
34
- # Offense count: 1
35
- # This cop supports safe autocorrection (--autocorrect).
36
- # Configuration parameters: EnforcedStyleForMultiline.
37
- # SupportedStylesForMultiline: comma, consistent_comma, diff_comma, no_comma
38
- Style/TrailingCommaInHashLiteral:
39
- Exclude:
40
- - 'lib/canon/rspec_matchers.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/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Canon
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.