Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,5 @@ inherit_from: .rubocop_todo.yml
AllCops:
NewCops: enable
SuggestExtensions: false
TargetRubyVersion: 2.7
TargetRubyVersion: 3.2

Gemspec/DevelopmentDependencies:
Enabled: false

Gemspec/RequireMFA:
Enabled: false

Metrics/BlockLength:
AllowedMethods:
- describe

Style/Documentation:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma
48 changes: 36 additions & 12 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-01-11 09:46:54 UTC using RuboCop version 1.70.0.
# on 2026-03-21 05:26:15 UTC using RuboCop version 1.85.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
Bundler/OrderedGems:
# Offense count: 1
Gemspec/RequiredRubyVersion:
Exclude:
- 'Gemfile'
- 'genericode.gemspec'

# Offense count: 1
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
Expand All @@ -22,7 +19,7 @@ Lint/DuplicateBranch:

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AutoCorrect, CheckForMethodsWithNoSideEffects.
# Configuration parameters: CheckForMethodsWithNoSideEffects.
Lint/Void:
Exclude:
- 'lib/genericode/code_list.rb'
Expand All @@ -32,18 +29,18 @@ Lint/Void:
Metrics/AbcSize:
Max: 182

# Offense count: 2
# Offense count: 16
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 34
Max: 160

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 216

# Offense count: 5
# Offense count: 6
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 92
Expand All @@ -58,9 +55,36 @@ Metrics/MethodLength:
Metrics/PerceivedComplexity:
Max: 92

# Offense count: 2
# Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates.
# AllowedMethods: call
# WaywardPredicates: infinite?, nonzero?
Naming/PredicateMethod:
Exclude:
- 'lib/genericode/cli/converter.rb'
- 'lib/genericode/cli/validator.rb'

# Offense count: 37
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false

# Offense count: 53
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'genericode.gemspec'
- 'lib/genericode/cli/code_lister.rb'
- 'lib/genericode/cli/code_lookup.rb'
- 'lib/genericode/cli/commands.rb'
- 'lib/genericode/cli/converter.rb'
- 'lib/genericode/cli/validator.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Layout/LineLength:
Max: 121
15 changes: 8 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

source "https://rubygems.org"
source 'https://rubygems.org'

# Specify your gem's dependencies in genericode.gemspec
gemspec

gem "nokogiri"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0"
gem "rubocop"
gem "rubocop-performance"
gem "xml-c14n"
gem 'canon'
gem 'lutaml-model', github: 'lutaml/lutaml-model', ref: 'main'
gem 'nokogiri'
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.0'
gem 'rubocop'
gem 'rubocop-performance'
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

require "rubocop/rake_task"
require 'rubocop/rake_task'

RuboCop::RakeTask.new

Expand Down
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "genericode"
require 'bundler/setup'
require 'genericode'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require "irb"
require 'irb'
IRB.start(__FILE__)
4 changes: 2 additions & 2 deletions exe/genericode
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative "../lib/genericode"
require_relative "../lib/genericode/cli"
require_relative '../lib/genericode'
require_relative '../lib/genericode/cli'

Genericode::Cli::Commands.start(ARGV)
33 changes: 17 additions & 16 deletions genericode.gemspec
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# frozen_string_literal: true

require_relative "lib/genericode/version"
require_relative 'lib/genericode/version'

Gem::Specification.new do |spec|
spec.name = "genericode"
spec.name = 'genericode'
spec.version = Genericode::VERSION
spec.authors = ["Ribose Inc."]
spec.authors = ['Ribose Inc.']
spec.email = ["open.source@ribose.com'"]

spec.summary = "Parser and generator for OASIS Genericode"
spec.description = "Parser and generator for OASIS Genericode"
spec.homepage = "https://github.com/lutaml/genericode"
spec.required_ruby_version = ">= 2.7.0"
spec.summary = 'Parser and generator for OASIS Genericode'
spec.description = 'Parser and generator for OASIS Genericode'
spec.homepage = 'https://github.com/lutaml/genericode'
spec.required_ruby_version = '>= 2.7.0'

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage
spec.metadata["changelog_uri"] = "https://github.com/lutaml/genericode/releases"
spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = spec.homepage
spec.metadata['changelog_uri'] = 'https://github.com/lutaml/genericode/releases'
spec.metadata['rubygems_mfa_required'] = 'true'

gemspec = File.basename(__FILE__)
spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
Expand All @@ -24,12 +25,12 @@ Gem::Specification.new do |spec|
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
end
end
spec.bindir = "exe"
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_dependency "csv"
spec.add_dependency "lutaml-model", "~> 0.7"
spec.add_dependency "tabulo"
spec.add_dependency "thor"
spec.add_dependency 'csv'
spec.add_dependency 'lutaml-model', '~>0.8.0'
spec.add_dependency 'table_tennis', '~>0.0.7'
spec.add_dependency 'thor'
end
9 changes: 4 additions & 5 deletions lib/genericode.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# frozen_string_literal: true

require "lutaml/model"
require 'lutaml/model'

Lutaml::Model::Config.configure do |config|
require "lutaml/model/xml_adapter/nokogiri_adapter"
config.xml_adapter = Lutaml::Model::XmlAdapter::NokogiriAdapter
config.xml_adapter_type = :nokogiri
end

require_relative "genericode/version"
require_relative "genericode/code_list"
require_relative 'genericode/version'
require_relative 'genericode/code_list'

module Genericode
class Error < StandardError; end
Expand Down
31 changes: 15 additions & 16 deletions lib/genericode/agency.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require "lutaml/model"
require 'lutaml/model'

require_relative "general_identifier"
require_relative "long_name"
require_relative "short_name"
require_relative "json/short_name_mixin"
require_relative "utils"
require_relative 'general_identifier'
require_relative 'long_name'
require_relative 'short_name'
require_relative 'json/short_name_mixin'
require_relative 'utils'

module Genericode
class Agency < Lutaml::Model::Serializable
Expand All @@ -17,34 +17,33 @@ class Agency < Lutaml::Model::Serializable
attribute :identifier, GeneralIdentifier, collection: true

json do
map "ShortName", to: :short_name, with: { from: :short_name_from_json, to: :short_name_to_json }
map "LongName", to: :long_name, with: { from: :long_name_from_json, to: :long_name_to_json }
map "Identifier", to: :identifier, with: { from: :identifier_from_json, to: :identifier_to_json }
map 'ShortName', to: :short_name, with: { from: :short_name_from_json, to: :short_name_to_json }
map 'LongName', to: :long_name, with: { from: :long_name_from_json, to: :long_name_to_json }
map 'Identifier', to: :identifier, with: { from: :identifier_from_json, to: :identifier_to_json }
end

def long_name_from_json(model, value)
model.long_name = LongName.of_json(Utils.array_wrap(value))
end

def long_name_to_json(model, doc)
doc["LongName"] = LongName.as_json(Utils.one_or_all(model.long_name))
doc['LongName'] = LongName.as_json(Utils.one_or_all(model.long_name))
end

def identifier_from_json(model, value)
model.identifier = GeneralIdentifier.of_json(Utils.array_wrap(value))
end

def identifier_to_json(model, doc)
doc["Identifier"] = GeneralIdentifier.as_json(Utils.one_or_all(model.identifier))
doc['Identifier'] = GeneralIdentifier.as_json(Utils.one_or_all(model.identifier))
end

xml do
root "Agency"
namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
element 'Agency'

map_element "ShortName", to: :short_name, prefix: nil, namespace: nil
map_element "LongName", to: :long_name, prefix: nil, namespace: nil
map_element "Identifier", to: :identifier, prefix: nil, namespace: nil
map_element 'ShortName', to: :short_name
map_element 'LongName', to: :long_name
map_element 'Identifier', to: :identifier
end
end
end
19 changes: 9 additions & 10 deletions lib/genericode/annotation.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
# frozen_string_literal: true

require "lutaml/model"
require 'lutaml/model'

require_relative "any_other_content"
require_relative "any_other_language_content"
require_relative 'any_other_content'
require_relative 'any_other_language_content'

module Genericode
class Annotation < Lutaml::Model::Serializable
attribute :description, AnyOtherLanguageContent, collection: true
attribute :app_info, AnyOtherContent

json do
map "Description", to: :description
map "AppInfo", to: :app_info, render_nil: true
map 'Description', to: :description
map 'AppInfo', to: :app_info, render_nil: true
end

def self.of_json(hash, **)
hash = { "AppInfo" => hash } if hash.any?
hash = { 'AppInfo' => hash } if hash.any?

super
end

xml do
root "Annotation"
namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
element 'Annotation'

map_element "Description", to: :description, prefix: nil, namespace: nil
map_element "AppInfo", to: :app_info, prefix: nil, namespace: nil, value_map: { to: { nil: :empty } }
map_element 'Description', to: :description
map_element 'AppInfo', to: :app_info, value_map: { to: { nil: :empty } }
end
end
end
5 changes: 2 additions & 3 deletions lib/genericode/any_other_content.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# frozen_string_literal: true

require "lutaml/model"
require 'lutaml/model'

module Genericode
class AnyOtherContent < Lutaml::Model::Serializable
xml do
root "AnyOtherContent"
namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
element 'AnyOtherContent'
end
end
end
Loading
Loading