genericode 0.1.2 → 0.2.0

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -28
  3. data/.rubocop_todo.yml +36 -12
  4. data/Rakefile +3 -3
  5. data/exe/genericode +2 -2
  6. data/lib/genericode/agency.rb +15 -16
  7. data/lib/genericode/annotation.rb +9 -10
  8. data/lib/genericode/any_other_content.rb +2 -3
  9. data/lib/genericode/any_other_language_content.rb +6 -6
  10. data/lib/genericode/canonical_uri.rb +3 -3
  11. data/lib/genericode/cli/code_lister.rb +19 -14
  12. data/lib/genericode/cli/code_lookup.rb +1 -1
  13. data/lib/genericode/cli/commands.rb +21 -18
  14. data/lib/genericode/cli/converter.rb +10 -11
  15. data/lib/genericode/cli/validator.rb +12 -5
  16. data/lib/genericode/cli.rb +1 -1
  17. data/lib/genericode/code_list.rb +64 -63
  18. data/lib/genericode/code_list_ref.rb +12 -13
  19. data/lib/genericode/code_list_set.rb +20 -21
  20. data/lib/genericode/code_list_set_ref.rb +14 -14
  21. data/lib/genericode/column.rb +33 -34
  22. data/lib/genericode/column_ref.rb +18 -19
  23. data/lib/genericode/column_set.rb +24 -25
  24. data/lib/genericode/column_set_ref.rb +9 -10
  25. data/lib/genericode/data.rb +14 -15
  26. data/lib/genericode/data_restrictions.rb +7 -8
  27. data/lib/genericode/datatype_facet.rb +8 -9
  28. data/lib/genericode/gc_namespace.rb +12 -0
  29. data/lib/genericode/general_identifier.rb +9 -9
  30. data/lib/genericode/identification.rb +37 -39
  31. data/lib/genericode/json/canonical_uri_mixin.rb +1 -1
  32. data/lib/genericode/json/short_name_mixin.rb +1 -1
  33. data/lib/genericode/key.rb +28 -29
  34. data/lib/genericode/key_column_ref.rb +7 -8
  35. data/lib/genericode/key_ref.rb +13 -14
  36. data/lib/genericode/long_name.rb +11 -11
  37. data/lib/genericode/mime_typed_uri.rb +5 -6
  38. data/lib/genericode/row.rb +8 -9
  39. data/lib/genericode/short_name.rb +7 -7
  40. data/lib/genericode/simple_code_list.rb +9 -10
  41. data/lib/genericode/simple_value.rb +3 -4
  42. data/lib/genericode/value.rb +14 -15
  43. data/lib/genericode/version.rb +1 -1
  44. data/lib/genericode.rb +4 -5
  45. metadata +14 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45525e09245553fcda6cb3606ec8f7b17c0fde0daf6507c41e47008d5e8dce43
4
- data.tar.gz: 66c0b7b056d47c096d736176d9c575df8fba8c830f539d14e076b43a6f07cda8
3
+ metadata.gz: 3857740082db34080d9c007ae47c022e652e34852943ba6e86142e5e83a727cc
4
+ data.tar.gz: 436afb59bc58bec8027daa7f72f5142275b0e58dfd4141659f1b35eb87e5117e
5
5
  SHA512:
6
- metadata.gz: d6dd2ebe439fde9ab7584ef67e149b3d79b026ae980b8beec200c5fd99a45e95c35b70663bfd8d27566095778394ce6a65ad2f4e7ff72b4706b7028c94ba55a5
7
- data.tar.gz: 59951937dd0cd26496fe64e13f9ba70c12ed7d2757609ebfa10633e4d21a233fae230fc234b7da559f4bc12e1c121b029bec786af445f74d6fd5a703dcff83b0
6
+ metadata.gz: 05a154e0eb406023445a3f11b051f5f6b10cdf27384033507717da03abd178071bb0e4958863dd75b979297cb3b761327ee7e8d03fb6f6387b6b7ac4b87996b9
7
+ data.tar.gz: f10872b3dfa5fb2a17c4d842fee2c2dda3b5d221d9f0bfdf9d8c9b5d29712490b20c2ea7a891180a29118f126618106178f4027feef67d5fcaf6f42a8211b208
data/.rubocop.yml CHANGED
@@ -3,32 +3,5 @@ inherit_from: .rubocop_todo.yml
3
3
  AllCops:
4
4
  NewCops: enable
5
5
  SuggestExtensions: false
6
- TargetRubyVersion: 2.7
6
+ TargetRubyVersion: 3.2
7
7
 
8
- Gemspec/DevelopmentDependencies:
9
- Enabled: false
10
-
11
- Gemspec/RequireMFA:
12
- Enabled: false
13
-
14
- Metrics/BlockLength:
15
- AllowedMethods:
16
- - describe
17
-
18
- Style/Documentation:
19
- Enabled: false
20
-
21
- Style/StringLiterals:
22
- EnforcedStyle: double_quotes
23
-
24
- Style/StringLiteralsInInterpolation:
25
- EnforcedStyle: double_quotes
26
-
27
- Style/TrailingCommaInArguments:
28
- EnforcedStyleForMultiline: consistent_comma
29
-
30
- Style/TrailingCommaInArrayLiteral:
31
- EnforcedStyleForMultiline: consistent_comma
32
-
33
- Style/TrailingCommaInHashLiteral:
34
- EnforcedStyleForMultiline: consistent_comma
data/.rubocop_todo.yml CHANGED
@@ -1,18 +1,15 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2025-01-11 09:46:54 UTC using RuboCop version 1.70.0.
3
+ # on 2026-03-21 05:26:15 UTC using RuboCop version 1.85.1.
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: 4
10
- # This cop supports safe autocorrection (--autocorrect).
11
- # Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
12
- # Include: **/*.gemfile, **/Gemfile, **/gems.rb
13
- Bundler/OrderedGems:
9
+ # Offense count: 1
10
+ Gemspec/RequiredRubyVersion:
14
11
  Exclude:
15
- - 'Gemfile'
12
+ - 'genericode.gemspec'
16
13
 
17
14
  # Offense count: 1
18
15
  # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
@@ -22,7 +19,7 @@ Lint/DuplicateBranch:
22
19
 
23
20
  # Offense count: 1
24
21
  # This cop supports safe autocorrection (--autocorrect).
25
- # Configuration parameters: AutoCorrect, CheckForMethodsWithNoSideEffects.
22
+ # Configuration parameters: CheckForMethodsWithNoSideEffects.
26
23
  Lint/Void:
27
24
  Exclude:
28
25
  - 'lib/genericode/code_list.rb'
@@ -32,18 +29,18 @@ Lint/Void:
32
29
  Metrics/AbcSize:
33
30
  Max: 182
34
31
 
35
- # Offense count: 2
32
+ # Offense count: 16
36
33
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
37
34
  # AllowedMethods: refine
38
35
  Metrics/BlockLength:
39
- Max: 34
36
+ Max: 160
40
37
 
41
38
  # Offense count: 1
42
39
  # Configuration parameters: CountComments, CountAsOne.
43
40
  Metrics/ClassLength:
44
41
  Max: 216
45
42
 
46
- # Offense count: 5
43
+ # Offense count: 6
47
44
  # Configuration parameters: AllowedMethods, AllowedPatterns.
48
45
  Metrics/CyclomaticComplexity:
49
46
  Max: 92
@@ -58,9 +55,36 @@ Metrics/MethodLength:
58
55
  Metrics/PerceivedComplexity:
59
56
  Max: 92
60
57
 
58
+ # Offense count: 2
59
+ # Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates.
60
+ # AllowedMethods: call
61
+ # WaywardPredicates: infinite?, nonzero?
62
+ Naming/PredicateMethod:
63
+ Exclude:
64
+ - 'lib/genericode/cli/converter.rb'
65
+ - 'lib/genericode/cli/validator.rb'
66
+
67
+ # Offense count: 37
68
+ # Configuration parameters: AllowedConstants.
69
+ Style/Documentation:
70
+ Enabled: false
71
+
72
+ # Offense count: 53
73
+ # This cop supports safe autocorrection (--autocorrect).
74
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
75
+ # SupportedStyles: single_quotes, double_quotes
76
+ Style/StringLiterals:
77
+ Exclude:
78
+ - 'genericode.gemspec'
79
+ - 'lib/genericode/cli/code_lister.rb'
80
+ - 'lib/genericode/cli/code_lookup.rb'
81
+ - 'lib/genericode/cli/commands.rb'
82
+ - 'lib/genericode/cli/converter.rb'
83
+ - 'lib/genericode/cli/validator.rb'
84
+
61
85
  # Offense count: 2
62
86
  # This cop supports safe autocorrection (--autocorrect).
63
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
87
+ # Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
64
88
  # URISchemes: http, https
65
89
  Layout/LineLength:
66
90
  Max: 121
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require "rubocop/rake_task"
8
+ require 'rubocop/rake_task'
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
data/exe/genericode CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "../lib/genericode"
5
- require_relative "../lib/genericode/cli"
4
+ require_relative '../lib/genericode'
5
+ require_relative '../lib/genericode/cli'
6
6
 
7
7
  Genericode::Cli::Commands.start(ARGV)
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "lutaml/model"
3
+ require 'lutaml/model'
4
4
 
5
- require_relative "general_identifier"
6
- require_relative "long_name"
7
- require_relative "short_name"
8
- require_relative "json/short_name_mixin"
9
- require_relative "utils"
5
+ require_relative 'general_identifier'
6
+ require_relative 'long_name'
7
+ require_relative 'short_name'
8
+ require_relative 'json/short_name_mixin'
9
+ require_relative 'utils'
10
10
 
11
11
  module Genericode
12
12
  class Agency < Lutaml::Model::Serializable
@@ -17,9 +17,9 @@ module Genericode
17
17
  attribute :identifier, GeneralIdentifier, collection: true
18
18
 
19
19
  json do
20
- map "ShortName", to: :short_name, with: { from: :short_name_from_json, to: :short_name_to_json }
21
- map "LongName", to: :long_name, with: { from: :long_name_from_json, to: :long_name_to_json }
22
- map "Identifier", to: :identifier, with: { from: :identifier_from_json, to: :identifier_to_json }
20
+ map 'ShortName', to: :short_name, with: { from: :short_name_from_json, to: :short_name_to_json }
21
+ map 'LongName', to: :long_name, with: { from: :long_name_from_json, to: :long_name_to_json }
22
+ map 'Identifier', to: :identifier, with: { from: :identifier_from_json, to: :identifier_to_json }
23
23
  end
24
24
 
25
25
  def long_name_from_json(model, value)
@@ -27,7 +27,7 @@ module Genericode
27
27
  end
28
28
 
29
29
  def long_name_to_json(model, doc)
30
- doc["LongName"] = LongName.as_json(Utils.one_or_all(model.long_name))
30
+ doc['LongName'] = LongName.as_json(Utils.one_or_all(model.long_name))
31
31
  end
32
32
 
33
33
  def identifier_from_json(model, value)
@@ -35,16 +35,15 @@ module Genericode
35
35
  end
36
36
 
37
37
  def identifier_to_json(model, doc)
38
- doc["Identifier"] = GeneralIdentifier.as_json(Utils.one_or_all(model.identifier))
38
+ doc['Identifier'] = GeneralIdentifier.as_json(Utils.one_or_all(model.identifier))
39
39
  end
40
40
 
41
41
  xml do
42
- root "Agency"
43
- namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
42
+ element 'Agency'
44
43
 
45
- map_element "ShortName", to: :short_name, prefix: nil, namespace: nil
46
- map_element "LongName", to: :long_name, prefix: nil, namespace: nil
47
- map_element "Identifier", to: :identifier, prefix: nil, namespace: nil
44
+ map_element 'ShortName', to: :short_name
45
+ map_element 'LongName', to: :long_name
46
+ map_element 'Identifier', to: :identifier
48
47
  end
49
48
  end
50
49
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "lutaml/model"
3
+ require 'lutaml/model'
4
4
 
5
- require_relative "any_other_content"
6
- require_relative "any_other_language_content"
5
+ require_relative 'any_other_content'
6
+ require_relative 'any_other_language_content'
7
7
 
8
8
  module Genericode
9
9
  class Annotation < Lutaml::Model::Serializable
@@ -11,22 +11,21 @@ module Genericode
11
11
  attribute :app_info, AnyOtherContent
12
12
 
13
13
  json do
14
- map "Description", to: :description
15
- map "AppInfo", to: :app_info, render_nil: true
14
+ map 'Description', to: :description
15
+ map 'AppInfo', to: :app_info, render_nil: true
16
16
  end
17
17
 
18
18
  def self.of_json(hash, **)
19
- hash = { "AppInfo" => hash } if hash.any?
19
+ hash = { 'AppInfo' => hash } if hash.any?
20
20
 
21
21
  super
22
22
  end
23
23
 
24
24
  xml do
25
- root "Annotation"
26
- namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
25
+ element 'Annotation'
27
26
 
28
- map_element "Description", to: :description, prefix: nil, namespace: nil
29
- map_element "AppInfo", to: :app_info, prefix: nil, namespace: nil, render_nil: true
27
+ map_element 'Description', to: :description
28
+ map_element 'AppInfo', to: :app_info, value_map: { to: { nil: :empty } }
30
29
  end
31
30
  end
32
31
  end
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "lutaml/model"
3
+ require 'lutaml/model'
4
4
 
5
5
  module Genericode
6
6
  class AnyOtherContent < Lutaml::Model::Serializable
7
7
  xml do
8
- root "AnyOtherContent"
9
- namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
8
+ element 'AnyOtherContent'
10
9
  end
11
10
  end
12
11
  end
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "lutaml/model"
3
+ require 'lutaml/model'
4
+ require 'lutaml/xml/w3c'
4
5
 
5
6
  module Genericode
6
7
  class AnyOtherLanguageContent < Lutaml::Model::Serializable
7
- attribute :lang, :string
8
+ attribute :lang, Lutaml::Xml::W3c::XmlLangType
8
9
 
9
10
  json do
10
- map "lang", to: :lang
11
+ map 'lang', to: :lang
11
12
  end
12
13
 
13
14
  xml do
14
- root "AnyOtherLanguageContent"
15
- namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
15
+ element 'AnyOtherLanguageContent'
16
16
 
17
- map_attribute "lang", to: :lang, prefix: "xml", namespace: "http://www.w3.org/XML/1998/namespace"
17
+ map_attribute 'lang', to: :lang
18
18
  end
19
19
  end
20
20
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "lutaml/model"
4
- require "uri"
3
+ require 'lutaml/model'
4
+ require 'uri'
5
5
 
6
6
  module Genericode
7
7
  # Rule 4: Must be an absolute URI, must not be relative
@@ -9,7 +9,7 @@ module Genericode
9
9
  attribute :content, :string
10
10
 
11
11
  xml do
12
- root "CanonicalUri"
12
+ element 'CanonicalUri'
13
13
  map_content to: :content
14
14
  end
15
15
 
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../code_list"
4
- require "tabulo"
5
- require "csv"
3
+ require_relative '../code_list'
4
+ require 'table_tennis'
5
+ require 'csv'
6
6
 
7
7
  module Genericode
8
8
  module Cli
@@ -13,10 +13,16 @@ module Genericode
13
13
 
14
14
  # Validate data types
15
15
  code_list.validate_verbose.each do |error|
16
- raise Error, "#{error[:code]}: #{error[:message]}" if error[:code] == "INVALID_DATA_TYPE"
16
+ if error[:code] == 'INVALID_DATA_TYPE'
17
+ raise Error,
18
+ "#{error[:code]}: #{error[:message]}"
19
+ end
17
20
 
18
21
  # Ensure valid ColumnRefs
19
- raise Error, "#{error[:code]}: #{error[:message]}" if error[:code] == "INVALID_COLUMN_REF"
22
+ if error[:code] == 'INVALID_COLUMN_REF'
23
+ raise Error,
24
+ "#{error[:code]}: #{error[:message]}"
25
+ end
20
26
  end
21
27
 
22
28
  case format
@@ -40,26 +46,25 @@ module Genericode
40
46
  rows.each do |row|
41
47
  csv << columns.map do |col|
42
48
  value = row.value.find { |v| v.column_ref == col.id }
43
- value&.simple_value&.content || ""
49
+ value&.simple_value&.content || ''
44
50
  end
45
51
  end
46
- end.strip.encode("UTF-8")
52
+ end.strip.encode('UTF-8')
47
53
  end
48
54
 
49
55
  def list_table(code_list)
50
56
  columns = code_list.column_set.column
51
57
  rows = code_list.simple_code_list.row
52
58
 
53
- table = Tabulo::Table.new(rows) do |t|
54
- columns.each do |column|
55
- t.add_column(column.short_name.content) do |row|
56
- value = row.value.find { |v| v.column_ref == column.id }
57
- value&.simple_value&.content || ""
58
- end
59
+ headers = columns.map { |col| col.short_name.content }
60
+ data = rows.map do |row|
61
+ columns.map do |col|
62
+ value = row.value.find { |v| v.column_ref == col.id }
63
+ value&.simple_value&.content || ''
59
64
  end
60
65
  end
61
66
 
62
- table.to_s
67
+ TableTennis.render([headers] + data)
63
68
  end
64
69
  end
65
70
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../code_list"
3
+ require_relative '../code_list'
4
4
 
5
5
  module Genericode
6
6
  module Cli
@@ -1,52 +1,55 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "thor"
4
- require_relative "validator"
5
- require_relative "converter"
6
- require_relative "code_lister"
7
- require_relative "code_lookup"
3
+ require 'thor'
4
+ require_relative 'validator'
5
+ require_relative 'converter'
6
+ require_relative 'code_lister'
7
+ require_relative 'code_lookup'
8
8
 
9
9
  module Genericode
10
10
  module Cli
11
11
  class Commands < Thor
12
- desc "convert INPUT OUTPUT", "Convert between Genericode XML and JSON formats"
12
+ desc 'convert INPUT OUTPUT',
13
+ 'Convert between Genericode XML and JSON formats'
13
14
 
14
15
  def convert(input, output)
15
- puts "Conversion successful." if Converter.convert(input, output)
16
+ puts 'Conversion successful.' if Converter.convert(input, output)
16
17
  rescue Error => e
17
18
  puts "Conversion failed: #{e.message}"
18
19
  end
19
20
 
20
- desc "validate FILE", "Validate a Genericode file"
21
- option :verbose, type: :boolean, desc: "Show detailed validation results"
21
+ desc 'validate FILE', 'Validate a Genericode file'
22
+ option :verbose, type: :boolean, desc: 'Show detailed validation results'
22
23
 
23
24
  def validate(file)
24
25
  code_list = CodeList.from_file(file)
25
26
  if options[:verbose]
26
27
  results = code_list.validate_verbose
27
28
  if results.empty?
28
- puts "File is valid."
29
+ puts 'File is valid.'
29
30
  else
30
- puts "File is invalid. Issues found:"
31
+ puts 'File is invalid. Issues found:'
31
32
  results.each do |error|
32
33
  puts " [#{error[:code]}] #{error[:message]}"
33
34
  end
34
35
  end
35
36
  elsif code_list.valid?
36
- puts "File is valid."
37
+ puts 'File is valid.'
37
38
  else
38
- puts "File is invalid."
39
+ puts 'File is invalid.'
39
40
  end
40
41
  rescue Error => e
41
42
  puts "Validation failed: #{e.message}"
42
43
  end
43
44
 
44
- desc "list_codes FILE", "List all codes and their associated data in a Genericode file"
45
- option :format, type: :string, default: "tsv", enum: %w[tsv table], desc: "Output format (tsv or table)"
46
- option :output, type: :string, desc: "Output file path (default: stdout)"
45
+ desc 'list_codes FILE',
46
+ 'List all codes and their associated data in a Genericode file'
47
+ option :format, type: :string, default: 'tsv', enum: %w[tsv table],
48
+ desc: 'Output format (tsv or table)'
49
+ option :output, type: :string, desc: 'Output file path (default: stdout)'
47
50
 
48
51
  def list_codes(file)
49
- format = (options[:format] || "tsv").to_sym
52
+ format = (options[:format] || 'tsv').to_sym
50
53
  result = CodeLister.list_codes(file, format: format)
51
54
 
52
55
  if options[:output]
@@ -59,7 +62,7 @@ module Genericode
59
62
  puts "Listing codes failed: #{e.message}"
60
63
  end
61
64
 
62
- desc "lookup FILE PATH", "Look up a particular code using Genericode path"
65
+ desc 'lookup FILE PATH', 'Look up a particular code using Genericode path'
63
66
 
64
67
  def lookup(file, path)
65
68
  result = CodeLookup.lookup(file, path)
@@ -7,14 +7,20 @@ module Genericode
7
7
  input_format = File.extname(input_path)
8
8
  output_format = File.extname(output_path)
9
9
 
10
- raise Error, "Invalid input format" unless [".gc", ".gcj"].include?(input_format)
11
- raise Error, "Invalid output format" unless [".gc", ".gcj"].include?(output_format)
12
- raise Error, "Input and output formats are the same" if input_format == output_format
10
+ raise Error, 'Invalid input format' unless ['.gc',
11
+ '.gcj'].include?(input_format)
12
+ raise Error, 'Invalid output format' unless ['.gc',
13
+ '.gcj'].include?(output_format)
14
+
15
+ if input_format == output_format
16
+ raise Error,
17
+ 'Input and output formats are the same'
18
+ end
13
19
 
14
20
  # begin
15
21
  code_list = CodeList.from_file(input_path)
16
22
 
17
- result = if output_format == ".gcj"
23
+ result = if output_format == '.gcj'
18
24
  code_list.to_json
19
25
  else
20
26
  code_list.to_xml
@@ -22,13 +28,6 @@ module Genericode
22
28
 
23
29
  File.write(output_path, result)
24
30
  true
25
- # rescue JSON::ParserError => e
26
- # raise Error, "Invalid JSON in input file: #{e.message}"
27
- # rescue Shale::ParseError => e
28
- # raise Error, "Invalid XML in input file: #{e.message}"
29
- # rescue StandardError => e
30
- # raise Error, "Conversion error: #{e.message}"
31
- # end
32
31
  end
33
32
  end
34
33
  end
@@ -4,15 +4,22 @@ module Genericode
4
4
  module Cli
5
5
  class Validator
6
6
  def self.validate(file_path)
7
- raise Error, "File does not exist" unless File.exist?(file_path)
8
- raise Error, "Invalid file format" unless file_path.end_with?(".gc", ".gcj")
7
+ raise Error, 'File does not exist' unless File.exist?(file_path)
8
+ raise Error, 'Invalid file format' unless file_path.end_with?('.gc',
9
+ '.gcj')
9
10
 
10
11
  code_list = CodeList.from_file(file_path)
11
12
 
12
- raise Error, "No columns defined" if code_list.column_set.nil? || code_list.column_set.column.empty?
13
- raise Error, "No rows defined" if code_list.simple_code_list.nil? || code_list.simple_code_list.row.empty?
13
+ if code_list.column_set.nil? || code_list.column_set.column.empty?
14
+ raise Error,
15
+ 'No columns defined'
16
+ end
17
+ if code_list.simple_code_list.nil? || code_list.simple_code_list.row.empty?
18
+ raise Error,
19
+ 'No rows defined'
20
+ end
14
21
 
15
- raise Error, "Invalid Genericode structure" unless code_list.valid?
22
+ raise Error, 'Invalid Genericode structure' unless code_list.valid?
16
23
 
17
24
  true
18
25
  end
@@ -5,4 +5,4 @@ module Genericode
5
5
  end
6
6
  end
7
7
 
8
- require_relative "cli/commands"
8
+ require_relative 'cli/commands'