Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Tell dependabot to update GH Actions #28

Merged
merged 7 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
## [4.0.0](https://github.com/sequra/norma43_parser/compare/3.0.0...v4.0.0) (2024-06-18)


### ⚠ BREAKING CHANGES

* Drop Ruby support below 3

### Features

* Get IBANs from account instances ([#15](https://github.com/sequra/norma43_parser/issues/15)) ([c69d162](https://github.com/sequra/norma43_parser/commit/c69d162361b188f2b2d904b1958e3108be9a3939))


## v3.0.0 (2021-12-15)

### Breaking Changes

- Drop Ruby support below 2.6.


## v2.1.1 (2020-03-13)

### Enhancements
Expand Down
20 changes: 1 addition & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
PATH
remote: .
specs:
norma43_parser (4.1.0)
virtus (~> 1.0)
norma43_parser (4.0.0)
zeitwerk (~> 2.0)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.5.1)
equalizer (0.0.11)
ice_nine (0.11.2)
json (2.7.2)
json (2.7.2-java)
language_server-protocol (3.17.0.3)
Expand Down Expand Up @@ -66,14 +55,7 @@ GEM
ruby-progressbar (1.13.0)
strscan (3.1.0)
strscan (3.1.0-java)
thread_safe (0.3.6)
thread_safe (0.3.6-java)
unicode-display_width (2.5.0)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
zeitwerk (2.6.15)

PLATFORMS
Expand Down
2 changes: 0 additions & 2 deletions lib/norma43/models.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "virtus"

module Norma43
module Models
DEBIT_CODE = 1
Expand Down
70 changes: 51 additions & 19 deletions lib/norma43/models/account.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,62 @@
# frozen_string_literal: true

require "virtus"

module Norma43
module Models
class Account
include Virtus.model
include Mixins::AttributesAssignment

attr_accessor :bank_code,
:branch_code,
:account_number,
:start_date,
:end_date,
:balance_code,
:balance_amount,
:currency_code,
:information_mode_code,
:abbreviated_name,
:debit_entries,
:debit_amount,
:credit_entries,
:credit_amount,
:transactions

attribute :bank_code
attribute :branch_code
attribute :account_number
attribute :start_date
attribute :end_date
attribute :balance_code
attribute :balance_amount
attribute :currency_code
attribute :information_mode_code
attribute :abbreviated_name
attribute :debit_entries
attribute :debit_amount
attribute :credit_entries
attribute :credit_amount
attribute :transactions, Array[Transaction]
def initialize(attributes = EMPTY_ATTRIBUTES)
@bank_code,
@branch_code,
@account_number,
@start_date,
@end_date,
@balance_code,
@balance_amount,
@currency_code,
@information_mode_code,
@abbreviated_name,
@debit_entries,
@debit_amount,
@credit_entries,
@credit_amount,
transactions = Hash(attributes).values_at(
:bank_code,
:branch_code,
:account_number,
:start_date,
:end_date,
:balance_code,
:balance_amount,
:currency_code,
:information_mode_code,
:abbreviated_name,
:debit_entries,
:debit_amount,
:credit_entries,
:credit_amount,
:transactions)
@transactions = Array(transactions).map { |attrs| Transaction.new(attrs) }
end

def iban
@iban ||= SpanishIban.from_account(self)
SpanishIban.from_account(self)
end
end
end
Expand Down
20 changes: 13 additions & 7 deletions lib/norma43/models/additional_currency.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# frozen_string_literal: true

require "virtus"

module Norma43
module Models
class AdditionalCurrency
include Virtus.model
include Mixins::AttributesAssignment

attr_accessor :data_code, :currency_code, :amount, :free

attribute :data_code
attribute :currency_code
attribute :amount
attribute :free
def initialize(attributes = EMPTY_ATTRIBUTES)
@data_code,
@currency_code,
@amount,
@free = Hash(attributes).values_at(
:data_code,
:currency_code,
:amount,
:free)
end
end
end
end
17 changes: 11 additions & 6 deletions lib/norma43/models/additional_item.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# frozen_string_literal: true

require "virtus"

module Norma43
module Models
class AdditionalItem
include Virtus.model
include Mixins::AttributesAssignment

attr_accessor :data_code, :item_1, :item_2

attribute :data_code
attribute :item_1
attribute :item_2
def initialize(attributes = EMPTY_ATTRIBUTES)
@data_code,
@item_1,
@item_2 = Hash(attributes).values_at(
:data_code,
:item_1,
:item_2)
end
end
end
end
41 changes: 30 additions & 11 deletions lib/norma43/models/document.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
# frozen_string_literal: true

require "virtus"

module Norma43
module Models
class Document
include Virtus.model
include Mixins::AttributesAssignment

attr_accessor :id, :created_at, :delivery_number, :file_type, :name, :number_of_lines, :accounts

attribute :id
attribute :created_at
attribute :delivery_number
attribute :file_type
attribute :name
attribute :number_of_lines
attribute :accounts, Array[Account]
def initialize(attributes = EMPTY_ATTRIBUTES)
@id,
@created_at,
@delivery_number,
@file_type,
@name,
@number_of_lines,
accounts = Hash(attributes).values_at(
:id,
:created_at,
:delivery_number,
:file_type,
:name,
:number_of_lines,
:accounts)
@accounts = Array(accounts).map { |account| Account.new(account) }
end

# @deprecated Please ask each transaction inside accounts for their transaction_date instead
def transaction_date
accounts.map(&:date).compact.first
warn "[DEPRECATION] `transaction_date` is deprecated, use `#transaction_date` from transactions in `#accounts` instead"
date = nil

accounts.flat_map(&:transactions).each { |transaction|
date = transaction&.transaction_date
break unless date.nil?
}

date
end
end
end
Expand Down
33 changes: 33 additions & 0 deletions lib/norma43/models/mixins/attributes_assignment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module Norma43
module Models
module Mixins
module AttributesAssignment
EMPTY_ATTRIBUTES = {}.freeze

def attributes=(new_attributes)
Hash(new_attributes).each do |attr_name, attr_value|
attr_writer_method_name = "#{attr_name}=".to_sym
next unless public_methods(false).include?(attr_writer_method_name)

public_send(attr_writer_method_name, attr_value)
end
end

def attributes
instance_variables.map { |ivar_name|
attr_reader_method_name = ivar_name.to_s.delete_prefix("@").to_sym
next unless public_methods(false).include?(attr_reader_method_name)

attr_value = public_send(attr_reader_method_name)

[attr_reader_method_name, attr_value]
}.compact.to_h
end
alias_method :to_hash, :attributes # Implicit coercion for `Hash(model)`
alias_method :to_h, :attributes # Explicit coercion
end
end
end
end
56 changes: 41 additions & 15 deletions lib/norma43/models/transaction.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
# frozen_string_literal: true

require "virtus"

module Norma43
module Models
class Transaction
include Virtus.model
include Mixins::AttributesAssignment

attr_accessor :origin_branch_code,
:transaction_date,
:value_date,
:shared_item,
:own_item,
:amount_code,
:amount,
:document_number,
:reference_1,
:reference_2,
:additional_items,
:additional_currency

def initialize(attributes = EMPTY_ATTRIBUTES)
@origin_branch_code,
@transaction_date,
@value_date,
@shared_item,
@own_item,
@amount_code,
@amount,
@document_number,
@reference_1,
@reference_2,
additional_items,
additional_currency = Hash(attributes).values_at(
:origin_branch_code,
:transaction_date,
:value_date,
:shared_item,
:own_item,
:amount_code,
:amount,
:document_number,
:reference_1,
:reference_2)
@additional_items = Array(additional_items).map { |attrs| AdditionalItem.new(attrs) }
@additional_currency = AdditionalCurrency.new(additional_currency) if additional_currency
end

attribute :origin_branch_code
attribute :transaction_date
attribute :value_date
attribute :shared_item
attribute :own_item
attribute :amount_code
attribute :amount
attribute :document_number
attribute :reference_1
attribute :reference_2
attribute :additional_items, Array[AdditionalItem]
attribute :additional_currency, AdditionalCurrency
def debit?; self.amount_code == DEBIT_CODE end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/norma43/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Norma43
VERSION = "4.1.0"
VERSION = "4.0.0"
end
1 change: 0 additions & 1 deletion norma43_parser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_runtime_dependency "virtus", "~> 1.0"
spec.add_runtime_dependency "zeitwerk", "~> 2.0"

spec.add_development_dependency "rake", "~> 13.0"
Expand Down
Loading
Loading