From 7abfd043f9868d289ba9350e1429f6a83528504f Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Wed, 7 Aug 2024 14:24:40 +0200 Subject: [PATCH] Update Ruby versions --- .github/workflows/rspec.yml | 2 +- .gitignore | 1 + .rubocop.yml | 2 +- Rakefile | 8 ++++---- lib/xrechnung.rb | 4 +--- lib/xrechnung/currency.rb | 2 +- lib/xrechnung/invoice_line.rb | 4 +--- lib/xrechnung/legal_monetary_total.rb | 2 +- lib/xrechnung/price.rb | 4 +--- lib/xrechnung/quantity.rb | 3 +-- lib/xrechnung/version.rb | 2 +- spec/fixtures/ruby/allowance_charge.rb | 4 ++-- spec/fixtures/ruby/payment_means.rb | 4 ++-- spec/fixtures/ruby/tax_total.rb | 16 ++++++++-------- spec/xrechnung/party_legal_entity_spec.rb | 2 +- spec/xrechnung/party_spec.rb | 5 ++--- spec/xrechnung_spec.rb | 8 ++++---- xrechnung.gemspec | 16 ++++++++-------- 18 files changed, 41 insertions(+), 48 deletions(-) diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 1a53d21..c61ff4b 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -8,7 +8,7 @@ jobs: name: Ruby ${{ matrix.ruby }} strategy: matrix: - ruby: ['2.7', '3.0', '3.2'] + ruby: ['3.0', '3.2', '3.3'] steps: - uses: actions/checkout@v4 diff --git a/.gitignore b/.gitignore index e0d8d90..689fde3 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ .ruby-version .ruby-gemset .gems/ +*.gem # validator working directory validator/ diff --git a/.rubocop.yml b/.rubocop.yml index 8a82583..d9890af 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,7 +12,7 @@ AllCops: - Gemfile DisplayCopNames: true StyleGuideCopsOnly: false - TargetRubyVersion: 2.7 + TargetRubyVersion: 3.0 ## Layout Cops - https://docs.rubocop.org/rubocop/cops_layout.html diff --git a/Rakefile b/Rakefile index 2a48328..7eba426 100644 --- a/Rakefile +++ b/Rakefile @@ -4,19 +4,19 @@ require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -task :default => :spec +task default: :spec namespace :validator do VALIDATOR_SOURCES = { - tool: { + tool: { filename: "validator/validationtool-1.4.1-standalone.jar", release_url: "https://github.com/itplr-kosit/validator/releases/download/v1.4.1/validationtool-1.4.1.zip", }, scenarios: { filename: "validator/scenarios.xml", release_url: "https://github.com/itplr-kosit/validator-configuration-xrechnung/releases/download/release-2023-05-12/validator-configuration-xrechnung_2.3.1_2023-05-12.zip", - } - } + }, + }.freeze VALIDATOR_SOURCES.each do |_, v| base = Pathname.new(__dir__).join("validator") diff --git a/lib/xrechnung.rb b/lib/xrechnung.rb index ef9070d..f65b524 100644 --- a/lib/xrechnung.rb +++ b/lib/xrechnung.rb @@ -270,9 +270,7 @@ def to_xml(indent: 2, target: "") xml.cbc :TaxCurrencyCode, tax_currency_code xml.cbc :BuyerReference, buyer_reference - unless self.class.members[:invoice_period].optional && invoice_period.nil? - invoice_period&.to_xml(xml) - end + invoice_period&.to_xml(xml) unless self.class.members[:invoice_period].optional && invoice_period.nil? xml.cac :OrderReference do xml.cbc :ID, purchase_order_reference diff --git a/lib/xrechnung/currency.rb b/lib/xrechnung/currency.rb index 7aa189b..16f8c47 100644 --- a/lib/xrechnung/currency.rb +++ b/lib/xrechnung/currency.rb @@ -8,7 +8,7 @@ def value_to_s end def xml_args - [value_to_s, currencyID: currency_id] + [value_to_s, { currencyID: currency_id }] end end diff --git a/lib/xrechnung/invoice_line.rb b/lib/xrechnung/invoice_line.rb index 375cea0..ea62296 100644 --- a/lib/xrechnung/invoice_line.rb +++ b/lib/xrechnung/invoice_line.rb @@ -42,9 +42,7 @@ def to_xml(xml) xml.cbc :InvoicedQuantity, invoiced_quantity.amount_to_s, unitCode: invoiced_quantity.unit_code xml.cbc :LineExtensionAmount, *line_extension_amount.xml_args - unless self.class.members[:invoice_period].optional && invoice_period.nil? - invoice_period&.to_xml(xml) - end + invoice_period&.to_xml(xml) unless self.class.members[:invoice_period].optional && invoice_period.nil? item&.to_xml(xml) price&.to_xml(xml) end diff --git a/lib/xrechnung/legal_monetary_total.rb b/lib/xrechnung/legal_monetary_total.rb index 4536be9..4609819 100644 --- a/lib/xrechnung/legal_monetary_total.rb +++ b/lib/xrechnung/legal_monetary_total.rb @@ -43,7 +43,7 @@ def to_xml(xml) self.class.members.each_key do |name| next if self[name].nil? - xml.cbc :"#{name.to_s.split("_").map(&:capitalize).join}", *self[name].xml_args + xml.cbc :"#{name.to_s.split('_').map(&:capitalize).join}", *self[name].xml_args end xml.target! end diff --git a/lib/xrechnung/price.rb b/lib/xrechnung/price.rb index 94e18fd..200a54c 100644 --- a/lib/xrechnung/price.rb +++ b/lib/xrechnung/price.rb @@ -15,9 +15,7 @@ class Price member :allowance_charge, type: Xrechnung::AllowanceCharge def initialize(**kwargs) - unless kwargs[:price_amount].is_a?(Currency) - kwargs[:price_amount] = Currency::EUR(kwargs[:price_amount]) - end + kwargs[:price_amount] = Currency::EUR(kwargs[:price_amount]) unless kwargs[:price_amount].is_a?(Currency) super(**kwargs) end diff --git a/lib/xrechnung/quantity.rb b/lib/xrechnung/quantity.rb index 88b171a..7ef96ff 100644 --- a/lib/xrechnung/quantity.rb +++ b/lib/xrechnung/quantity.rb @@ -4,9 +4,8 @@ def amount_to_s format("%0.2f", amount) end - def xml_args - [amount_to_s, unitCode: unit_code] + [amount_to_s, { unitCode: unit_code }] end end end diff --git a/lib/xrechnung/version.rb b/lib/xrechnung/version.rb index d30bc0c..443bda1 100644 --- a/lib/xrechnung/version.rb +++ b/lib/xrechnung/version.rb @@ -1,3 +1,3 @@ module Xrechnung - VERSION = "0.3.0" + VERSION = "0.3.0".freeze end diff --git a/spec/fixtures/ruby/allowance_charge.rb b/spec/fixtures/ruby/allowance_charge.rb index 6db0dc8..302d339 100644 --- a/spec/fixtures/ruby/allowance_charge.rb +++ b/spec/fixtures/ruby/allowance_charge.rb @@ -1,7 +1,7 @@ def build_allowance_charge Xrechnung::AllowanceCharge.new( charge_indicator: true, - amount: 0, - base_amount: 1294.30 + amount: 0, + base_amount: 1294.30, ) end diff --git a/spec/fixtures/ruby/payment_means.rb b/spec/fixtures/ruby/payment_means.rb index 57c96ee..c7fd612 100644 --- a/spec/fixtures/ruby/payment_means.rb +++ b/spec/fixtures/ruby/payment_means.rb @@ -2,7 +2,7 @@ def build_payment_means Xrechnung::PaymentMeans.new( - payment_means_code: 30, - payee_financial_account: build_payee_financial_account + payment_means_code: 30, + payee_financial_account: build_payee_financial_account, ) end diff --git a/spec/fixtures/ruby/tax_total.rb b/spec/fixtures/ruby/tax_total.rb index b8c13d1..482df5c 100644 --- a/spec/fixtures/ruby/tax_total.rb +++ b/spec/fixtures/ruby/tax_total.rb @@ -7,14 +7,14 @@ def build_tax_total build_tax_subtotal, Xrechnung::TaxSubtotal.new( - taxable_amount: Xrechnung::Currency::EUR(1285.70), - tax_amount: Xrechnung::Currency::EUR(90.00), - tax_category: Xrechnung::TaxCategory.new( - id: "S", - percent: 7, - tax_scheme_id: "VAT", - ), - ), + taxable_amount: Xrechnung::Currency::EUR(1285.70), + tax_amount: Xrechnung::Currency::EUR(90.00), + tax_category: Xrechnung::TaxCategory.new( + id: "S", + percent: 7, + tax_scheme_id: "VAT", + ), + ), ], ) end diff --git a/spec/xrechnung/party_legal_entity_spec.rb b/spec/xrechnung/party_legal_entity_spec.rb index 0cf573f..1bb3811 100644 --- a/spec/xrechnung/party_legal_entity_spec.rb +++ b/spec/xrechnung/party_legal_entity_spec.rb @@ -5,7 +5,7 @@ it "generates xml" do expect_xml_eq_fixture( build_party_legal_entity(company_id: "DE 214365879"), - "party_legal_entity" + "party_legal_entity", ) end end diff --git a/spec/xrechnung/party_spec.rb b/spec/xrechnung/party_spec.rb index 84c5026..a827196 100644 --- a/spec/xrechnung/party_spec.rb +++ b/spec/xrechnung/party_spec.rb @@ -1,7 +1,6 @@ -require 'spec_helper' +require "spec_helper" load("spec/fixtures/ruby/party.rb") - RSpec.describe Xrechnung::Party do let(:party) do build_party @@ -20,6 +19,6 @@ it "generates flat party" do party.nested = false - expect(to_xml(party)).to_not include "" + expect(to_xml(party)).not_to include "" end end diff --git a/spec/xrechnung_spec.rb b/spec/xrechnung_spec.rb index e6f7fcd..9bf7e54 100644 --- a/spec/xrechnung_spec.rb +++ b/spec/xrechnung_spec.rb @@ -11,7 +11,7 @@ end it "has a version number" do - expect(Xrechnung::VERSION).not_to be nil + expect(Xrechnung::VERSION).not_to be_nil end # rubocop:disable RSpec/ExampleLength @@ -39,7 +39,7 @@ doc.accounting_supplier_party = build_party doc.accounting_customer_party = Xrechnung::Party.new( - postal_address: Xrechnung::PostalAddress.new( + postal_address: Xrechnung::PostalAddress.new( street_name: "Malerweg 2", additional_street_name: "Hinterhof A", city_name: "Großstadt", @@ -50,10 +50,10 @@ party_identification: Xrechnung::PartyIdentification.new( id: "70012", ), - party_legal_entity: Xrechnung::PartyLegalEntity.new( + party_legal_entity: Xrechnung::PartyLegalEntity.new( registration_name: "Bauamt GmbH & Co KG", ), - contact: Xrechnung::Contact.new( + contact: Xrechnung::Contact.new( name: "Manfred Mustermann", telephone: "+49 12345 98 765 - 44", electronic_mail: "manfred.mustermann@bauamt.de", diff --git a/xrechnung.gemspec b/xrechnung.gemspec index 89a7a7f..1984e2c 100644 --- a/xrechnung.gemspec +++ b/xrechnung.gemspec @@ -1,4 +1,4 @@ -require_relative 'lib/xrechnung/version' +require_relative "lib/xrechnung/version" Gem::Specification.new do |spec| spec.name = "xrechnung" @@ -6,19 +6,19 @@ Gem::Specification.new do |spec| spec.authors = ["Julian Kornberger"] spec.email = ["jk+github@digineo.de"] - spec.summary = %q{Library to create invoices in the XRechnung format.} - spec.homepage = "https://github.com/digineo/xrechnung" - spec.license = "MIT" - spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0") + spec.summary = "Library to create invoices in the XRechnung format." + spec.homepage = "https://github.com/digineo/xrechnung" + spec.license = "MIT" + spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0") - spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "https://github.com/digineo/xrechnung" # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do + spec.files = Dir.chdir(File.expand_path(__dir__)) { `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - end + } spec.require_paths = ["lib"]