gobl 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 +7 -0
- data/data/tax/ES.json +841 -0
- data/data/tax/FR.json +47 -0
- data/data/tax/GB.json +56 -0
- data/data/tax/NL.json +60 -0
- data/home/cavalle/workspace/invopop/gobl.ruby/gobl.gemspec +30 -0
- data/lib/extensions.rb +12 -0
- data/lib/gobl/bill/advances.rb +90 -0
- data/lib/gobl/bill/charge.rb +121 -0
- data/lib/gobl/bill/delivery.rb +79 -0
- data/lib/gobl/bill/discount.rb +121 -0
- data/lib/gobl/bill/exchange_rates.rb +90 -0
- data/lib/gobl/bill/invoice.rb +209 -0
- data/lib/gobl/bill/invoice_type.rb +163 -0
- data/lib/gobl/bill/line.rb +121 -0
- data/lib/gobl/bill/line_charge.rb +79 -0
- data/lib/gobl/bill/line_discount.rb +79 -0
- data/lib/gobl/bill/ordering.rb +58 -0
- data/lib/gobl/bill/outlay.rb +107 -0
- data/lib/gobl/bill/payment.rb +79 -0
- data/lib/gobl/bill/preceding.rb +114 -0
- data/lib/gobl/bill/scheme_keys.rb +90 -0
- data/lib/gobl/bill/tax.rb +72 -0
- data/lib/gobl/bill/totals.rb +135 -0
- data/lib/gobl/cal/date.rb +106 -0
- data/lib/gobl/cal/period.rb +63 -0
- data/lib/gobl/config.rb +14 -0
- data/lib/gobl/currency/code.rb +322 -0
- data/lib/gobl/currency/exchange_rate.rb +65 -0
- data/lib/gobl/document.rb +70 -0
- data/lib/gobl/dsig/digest.rb +65 -0
- data/lib/gobl/dsig/signature.rb +106 -0
- data/lib/gobl/envelope.rb +77 -0
- data/lib/gobl/header.rb +98 -0
- data/lib/gobl/i18n/string.rb +72 -0
- data/lib/gobl/id.rb +80 -0
- data/lib/gobl/l10n/code.rb +106 -0
- data/lib/gobl/l10n/country_code.rb +405 -0
- data/lib/gobl/note/message.rb +72 -0
- data/lib/gobl/num/amount.rb +248 -0
- data/lib/gobl/num/percentage.rb +84 -0
- data/lib/gobl/operations/service_error.rb +10 -0
- data/lib/gobl/operations/validation_result.rb +46 -0
- data/lib/gobl/operations.rb +170 -0
- data/lib/gobl/org/address.rb +156 -0
- data/lib/gobl/org/code.rb +106 -0
- data/lib/gobl/org/coordinates.rb +79 -0
- data/lib/gobl/org/email.rb +79 -0
- data/lib/gobl/org/inbox.rb +86 -0
- data/lib/gobl/org/item.rb +121 -0
- data/lib/gobl/org/item_code.rb +65 -0
- data/lib/gobl/org/key.rb +106 -0
- data/lib/gobl/org/meta.rb +72 -0
- data/lib/gobl/org/name.rb +114 -0
- data/lib/gobl/org/note.rb +79 -0
- data/lib/gobl/org/note_key.rb +181 -0
- data/lib/gobl/org/party.rb +135 -0
- data/lib/gobl/org/person.rb +100 -0
- data/lib/gobl/org/registration.rb +99 -0
- data/lib/gobl/org/source_key.rb +161 -0
- data/lib/gobl/org/tax_identity.rb +93 -0
- data/lib/gobl/org/telephone.rb +72 -0
- data/lib/gobl/org/unit.rb +204 -0
- data/lib/gobl/pay/advance.rb +107 -0
- data/lib/gobl/pay/card.rb +65 -0
- data/lib/gobl/pay/credit_transfer.rb +86 -0
- data/lib/gobl/pay/direct_debit.rb +72 -0
- data/lib/gobl/pay/due_date.rb +86 -0
- data/lib/gobl/pay/instructions.rb +114 -0
- data/lib/gobl/pay/method_key.rb +163 -0
- data/lib/gobl/pay/online.rb +65 -0
- data/lib/gobl/pay/term_key.rb +166 -0
- data/lib/gobl/pay/terms.rb +79 -0
- data/lib/gobl/stamp.rb +63 -0
- data/lib/gobl/struct.rb +48 -0
- data/lib/gobl/tax/category.rb +83 -0
- data/lib/gobl/tax/category_total.rb +87 -0
- data/lib/gobl/tax/combo.rb +79 -0
- data/lib/gobl/tax/localities.rb +90 -0
- data/lib/gobl/tax/locality.rb +72 -0
- data/lib/gobl/tax/rate.rb +77 -0
- data/lib/gobl/tax/rate_total.rb +82 -0
- data/lib/gobl/tax/rate_total_surcharge.rb +63 -0
- data/lib/gobl/tax/rate_value.rb +79 -0
- data/lib/gobl/tax/region.rb +100 -0
- data/lib/gobl/tax/scheme.rb +86 -0
- data/lib/gobl/tax/schemes.rb +90 -0
- data/lib/gobl/tax/set.rb +90 -0
- data/lib/gobl/tax/total.rb +65 -0
- data/lib/gobl/types.rb +17 -0
- data/lib/gobl/uuid/uuid.rb +106 -0
- data/lib/gobl/version.rb +5 -0
- data/lib/gobl.rb +41 -0
- data/lib/gobl_extensions/document_helper.rb +45 -0
- data/lib/gobl_extensions/envelope_helper.rb +15 -0
- data/lib/gobl_extensions/i18n/value_keys_helper.rb +27 -0
- data/lib/gobl_extensions/tax/region_helper.rb +41 -0
- metadata +225 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
## DO NOT EDIT - This file was generated automatically.
|
|
5
|
+
##
|
|
6
|
+
## Generated with GOBL v0.30.4
|
|
7
|
+
##
|
|
8
|
+
|
|
9
|
+
module GOBL
|
|
10
|
+
module Pay
|
|
11
|
+
# Instructions holds a set of instructions that determine how the payment has or should be made.
|
|
12
|
+
class Instructions < GOBL::Struct
|
|
13
|
+
# The Schema ID of the GOBL Instructions structure
|
|
14
|
+
SCHEMA_ID = 'https://gobl.org/draft-0/pay/instructions'
|
|
15
|
+
|
|
16
|
+
# @!attribute [r] key
|
|
17
|
+
# How payment is expected or has been arranged to be collected
|
|
18
|
+
# @return [MethodKey]
|
|
19
|
+
attribute :key, MethodKey
|
|
20
|
+
|
|
21
|
+
# @!attribute [r] detail
|
|
22
|
+
# Optional text description of the payment method
|
|
23
|
+
# @return [String]
|
|
24
|
+
attribute? :detail, GOBL::Types::String.optional
|
|
25
|
+
|
|
26
|
+
# @!attribute [r] ref
|
|
27
|
+
# Remittance information, a text value used to link the payment with the invoice.
|
|
28
|
+
# @return [String]
|
|
29
|
+
attribute? :ref, GOBL::Types::String.optional
|
|
30
|
+
|
|
31
|
+
# @!attribute [r] credit_transfer
|
|
32
|
+
# Instructions for sending payment via a bank transfer.
|
|
33
|
+
# @return [Array<CreditTransfer>]
|
|
34
|
+
attribute? :credit_transfer, GOBL::Types::Array.of(CreditTransfer).optional
|
|
35
|
+
|
|
36
|
+
# @!attribute [r] card
|
|
37
|
+
# Details of the payment that will be made via a credit or debit card.
|
|
38
|
+
# @return [Card]
|
|
39
|
+
attribute? :card, Card.optional
|
|
40
|
+
|
|
41
|
+
# @!attribute [r] direct_debit
|
|
42
|
+
# A group of terms that can be used by the customer or payer to consolidate direct debit payments.
|
|
43
|
+
# @return [DirectDebit]
|
|
44
|
+
attribute? :direct_debit, DirectDebit.optional
|
|
45
|
+
|
|
46
|
+
# @!attribute [r] online
|
|
47
|
+
# Array of online payment options
|
|
48
|
+
# @return [Array<Online>]
|
|
49
|
+
attribute? :online, GOBL::Types::Array.of(Online).optional
|
|
50
|
+
|
|
51
|
+
# @!attribute [r] notes
|
|
52
|
+
# Any additional instructions that may be required to make the payment.
|
|
53
|
+
# @return [String]
|
|
54
|
+
attribute? :notes, GOBL::Types::String.optional
|
|
55
|
+
|
|
56
|
+
# @!attribute [r] meta
|
|
57
|
+
# Non-structured additional data that may be useful.
|
|
58
|
+
# @return [GOBL::Org::Meta]
|
|
59
|
+
attribute? :meta, GOBL::Org::Meta.optional
|
|
60
|
+
|
|
61
|
+
# Creates a new object from a hash of GOBL data
|
|
62
|
+
#
|
|
63
|
+
# @param data [Hash] a hash of GOBL data
|
|
64
|
+
#
|
|
65
|
+
# @return [Instructions] the object created from the given data
|
|
66
|
+
def self.from_gobl!(data)
|
|
67
|
+
data = GOBL::Types::Hash[data]
|
|
68
|
+
|
|
69
|
+
new(
|
|
70
|
+
key: MethodKey.from_gobl!(data['key']),
|
|
71
|
+
detail: data['detail'],
|
|
72
|
+
ref: data['ref'],
|
|
73
|
+
credit_transfer: data['credit_transfer']&.map { |item| CreditTransfer.from_gobl!(item) },
|
|
74
|
+
card: data['card'] ? Card.from_gobl!(data['card']) : nil,
|
|
75
|
+
direct_debit: data['direct_debit'] ? DirectDebit.from_gobl!(data['direct_debit']) : nil,
|
|
76
|
+
online: data['online']&.map { |item| Online.from_gobl!(item) },
|
|
77
|
+
notes: data['notes'],
|
|
78
|
+
meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Returns a hash of GOBL data representing the current object
|
|
83
|
+
#
|
|
84
|
+
# @return [Hash] the array of GOBL data that represents the current object
|
|
85
|
+
def to_gobl
|
|
86
|
+
{
|
|
87
|
+
'key' => attributes[:key]&.to_gobl,
|
|
88
|
+
'detail' => attributes[:detail],
|
|
89
|
+
'ref' => attributes[:ref],
|
|
90
|
+
'credit_transfer' => attributes[:credit_transfer]&.map { |item| item&.to_gobl },
|
|
91
|
+
'card' => attributes[:card]&.to_gobl,
|
|
92
|
+
'direct_debit' => attributes[:direct_debit]&.to_gobl,
|
|
93
|
+
'online' => attributes[:online]&.map { |item| item&.to_gobl },
|
|
94
|
+
'notes' => attributes[:notes],
|
|
95
|
+
'meta' => attributes[:meta]&.to_gobl
|
|
96
|
+
}.compact
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# @!method self.new(attrs)
|
|
100
|
+
#
|
|
101
|
+
# Returns a {Instructions} object from a given hash of attributes. Nested
|
|
102
|
+
# attributes are supported: the constructor will instantiate the proper GOBL
|
|
103
|
+
# objects when nested hashes or arrays are given as part of the `attrs`
|
|
104
|
+
# parameter.
|
|
105
|
+
#
|
|
106
|
+
# The `new` method will only allow to create a new object if all attributes
|
|
107
|
+
# marked as mandatory and not calculated in the JSON schema are provided.
|
|
108
|
+
#
|
|
109
|
+
# @param attrs [Hash] the hash of attributes
|
|
110
|
+
#
|
|
111
|
+
# @return [Instructions] the object corresponding to the given input
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
## DO NOT EDIT - This file was generated automatically.
|
|
5
|
+
##
|
|
6
|
+
## Generated with GOBL v0.30.4
|
|
7
|
+
##
|
|
8
|
+
|
|
9
|
+
module GOBL
|
|
10
|
+
module Pay
|
|
11
|
+
# Method Key describes how a payment should be made
|
|
12
|
+
class MethodKey < GOBL::Struct
|
|
13
|
+
# The Schema ID of the GOBL MethodKey structure
|
|
14
|
+
SCHEMA_ID = 'https://gobl.org/draft-0/pay/instructions#/$defs/MethodKey'
|
|
15
|
+
|
|
16
|
+
# The enumeration of values of the object and their descriptions (Values different to these are not allowed)
|
|
17
|
+
ENUM = {
|
|
18
|
+
'any' => 'Any method available, no preference',
|
|
19
|
+
'card' => 'Credit or debit card',
|
|
20
|
+
'credit-transfer' => 'Send initiated bank or wire transfer',
|
|
21
|
+
'debit-transfer' => 'Receive initiated bank or wire transfer',
|
|
22
|
+
'cash' => 'Cash',
|
|
23
|
+
'direct-debit' => 'Direct debit',
|
|
24
|
+
'online' => 'Online or web payment'
|
|
25
|
+
}.freeze
|
|
26
|
+
|
|
27
|
+
attribute :_value, GOBL::Types::String.enum(*ENUM.keys)
|
|
28
|
+
private :_value
|
|
29
|
+
|
|
30
|
+
# Creates a new object from a GOBL value
|
|
31
|
+
#
|
|
32
|
+
# @param data [String] the GOBL value
|
|
33
|
+
#
|
|
34
|
+
# @return [MethodKey] the object created from the given data
|
|
35
|
+
def self.from_gobl!(data)
|
|
36
|
+
new(_value: data)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Returns a GOBL value representing the current object
|
|
40
|
+
#
|
|
41
|
+
# @return [String] the GOBL value that represents the current object
|
|
42
|
+
def to_gobl
|
|
43
|
+
_value
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Returns a {MethodKey} that corresponds to a given object. The object can be a
|
|
47
|
+
# `Symbol`, a `String` or anything coercible into one (via `#to_s`).
|
|
48
|
+
#
|
|
49
|
+
# @param object [Symbol, String, #to_s] the value of the object.
|
|
50
|
+
#
|
|
51
|
+
# @return [MethodKey] the object corresponding to the given value.
|
|
52
|
+
#
|
|
53
|
+
# @example Instantiating from a symbol
|
|
54
|
+
# method_key = GOBL::Pay::MethodKey.new(:any)
|
|
55
|
+
#
|
|
56
|
+
# @example Instantiating from a string
|
|
57
|
+
# method_key = GOBL::Pay::MethodKey.new('any')
|
|
58
|
+
def self.new(object)
|
|
59
|
+
case object
|
|
60
|
+
when Hash, self # internal use, not to be used in public calls
|
|
61
|
+
super
|
|
62
|
+
when Symbol
|
|
63
|
+
new find_by_sym(object)
|
|
64
|
+
else
|
|
65
|
+
super _value: object.to_s
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Returns the string representation of the current object
|
|
70
|
+
#
|
|
71
|
+
# @return [String] the string representation of the current object
|
|
72
|
+
def to_s
|
|
73
|
+
_value.to_s
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Returns the symbol representation of the current object
|
|
77
|
+
#
|
|
78
|
+
# @return [Symbol] the symbol representation of the current object
|
|
79
|
+
def to_sym
|
|
80
|
+
to_s.parameterize.underscore.to_sym
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Returns whether the current object is equivalent to a given one. In addition
|
|
84
|
+
# to {MethodKey} objects, the current object can be compared to a `Symbol`, a
|
|
85
|
+
# `String` or anything coercible into one (via `#to_s`)
|
|
86
|
+
#
|
|
87
|
+
# @param other [MethodKey, Symbol, String, #to_s] the other object to compare to
|
|
88
|
+
#
|
|
89
|
+
# @return [Boolean] `true` if the objects are equivalent, `false` otherwise
|
|
90
|
+
#
|
|
91
|
+
# @example Comparing to another {MethodKey} object
|
|
92
|
+
# method_key = GOBL::Pay::MethodKey.new('any')
|
|
93
|
+
# method_key == GOBL::Pay::MethodKey.new('any') #=> true
|
|
94
|
+
# method_key == GOBL::Pay::MethodKey.new('card') #=> false
|
|
95
|
+
#
|
|
96
|
+
# @example Comparing to a string
|
|
97
|
+
# method_key = GOBL::Pay::MethodKey.new('any')
|
|
98
|
+
# method_key == 'any' #=> true
|
|
99
|
+
# method_key == 'card' #=> false
|
|
100
|
+
#
|
|
101
|
+
# @example Comparing to a symbol
|
|
102
|
+
# method_key = GOBL::Pay::MethodKey.new('any')
|
|
103
|
+
# method_key == :any #=> true
|
|
104
|
+
# method_key == :card #=> false
|
|
105
|
+
def ==(other)
|
|
106
|
+
case other
|
|
107
|
+
when self.class
|
|
108
|
+
super
|
|
109
|
+
when Symbol
|
|
110
|
+
to_sym == other
|
|
111
|
+
else
|
|
112
|
+
to_s == other.to_s
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Returns an array with all the enumerated objects of this type
|
|
117
|
+
#
|
|
118
|
+
# @return [Array<MethodKey>] the array of enumerated objects
|
|
119
|
+
def self.all
|
|
120
|
+
ENUM.keys.map { |key| new(key) }
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# @api private
|
|
124
|
+
def self.find_by_sym(sym)
|
|
125
|
+
all.find { |object| object.to_sym == sym }
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# @api private
|
|
129
|
+
def self.find_by_inquirer(method_name)
|
|
130
|
+
method_name =~ /(.+)\?$/ && find_by_sym(Regexp.last_match(1).to_sym)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Returns the description of the current object
|
|
134
|
+
#
|
|
135
|
+
# @return [String] the description of the current object
|
|
136
|
+
def description
|
|
137
|
+
ENUM.fetch(_value, _value)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# @api private
|
|
141
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
142
|
+
self.class.find_by_inquirer(method_name) || super
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Enables dynamic value inquirers like `MethodKey#any?` for
|
|
146
|
+
# each of the declared enum values (see {ENUM}). Each inquirer returns a
|
|
147
|
+
# `Boolean` denoting whether the value equals the enquired value (`true`) or
|
|
148
|
+
# not (`false`)
|
|
149
|
+
#
|
|
150
|
+
# @example
|
|
151
|
+
# method_key = GOBL::Pay::MethodKey.new('any')
|
|
152
|
+
# method_key.any? # => true
|
|
153
|
+
# method_key.card? # => false
|
|
154
|
+
def method_missing(method_name, *args, &block)
|
|
155
|
+
if value = self.class.find_by_inquirer(method_name)
|
|
156
|
+
self == value
|
|
157
|
+
else
|
|
158
|
+
super
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
## DO NOT EDIT - This file was generated automatically.
|
|
5
|
+
##
|
|
6
|
+
## Generated with GOBL v0.30.4
|
|
7
|
+
##
|
|
8
|
+
|
|
9
|
+
module GOBL
|
|
10
|
+
module Pay
|
|
11
|
+
# Online provides the details required to make a payment online using a website
|
|
12
|
+
class Online < GOBL::Struct
|
|
13
|
+
# The Schema ID of the GOBL Online structure
|
|
14
|
+
SCHEMA_ID = 'https://gobl.org/draft-0/pay/instructions#/$defs/Online'
|
|
15
|
+
|
|
16
|
+
# @!attribute [r] name
|
|
17
|
+
# Descriptive name given to the online provider.
|
|
18
|
+
# @return [String]
|
|
19
|
+
attribute? :name, GOBL::Types::String.optional
|
|
20
|
+
|
|
21
|
+
# @!attribute [r] addr
|
|
22
|
+
# Full URL to be used for payment.
|
|
23
|
+
# @return [String]
|
|
24
|
+
attribute :addr, GOBL::Types::String
|
|
25
|
+
|
|
26
|
+
# Creates a new object from a hash of GOBL data
|
|
27
|
+
#
|
|
28
|
+
# @param data [Hash] a hash of GOBL data
|
|
29
|
+
#
|
|
30
|
+
# @return [Online] the object created from the given data
|
|
31
|
+
def self.from_gobl!(data)
|
|
32
|
+
data = GOBL::Types::Hash[data]
|
|
33
|
+
|
|
34
|
+
new(
|
|
35
|
+
name: data['name'],
|
|
36
|
+
addr: data['addr']
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Returns a hash of GOBL data representing the current object
|
|
41
|
+
#
|
|
42
|
+
# @return [Hash] the array of GOBL data that represents the current object
|
|
43
|
+
def to_gobl
|
|
44
|
+
{
|
|
45
|
+
'name' => attributes[:name],
|
|
46
|
+
'addr' => attributes[:addr]
|
|
47
|
+
}.compact
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# @!method self.new(attrs)
|
|
51
|
+
#
|
|
52
|
+
# Returns a {Online} object from a given hash of attributes. Nested
|
|
53
|
+
# attributes are supported: the constructor will instantiate the proper GOBL
|
|
54
|
+
# objects when nested hashes or arrays are given as part of the `attrs`
|
|
55
|
+
# parameter.
|
|
56
|
+
#
|
|
57
|
+
# The `new` method will only allow to create a new object if all attributes
|
|
58
|
+
# marked as mandatory and not calculated in the JSON schema are provided.
|
|
59
|
+
#
|
|
60
|
+
# @param attrs [Hash] the hash of attributes
|
|
61
|
+
#
|
|
62
|
+
# @return [Online] the object corresponding to the given input
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
## DO NOT EDIT - This file was generated automatically.
|
|
5
|
+
##
|
|
6
|
+
## Generated with GOBL v0.30.4
|
|
7
|
+
##
|
|
8
|
+
|
|
9
|
+
module GOBL
|
|
10
|
+
module Pay
|
|
11
|
+
# Payment terms key
|
|
12
|
+
class TermKey < GOBL::Struct
|
|
13
|
+
# The Schema ID of the GOBL TermKey structure
|
|
14
|
+
SCHEMA_ID = 'https://gobl.org/draft-0/pay/terms#/$defs/TermKey'
|
|
15
|
+
|
|
16
|
+
# The enumeration of values of the object and their descriptions (Values different to these are not allowed)
|
|
17
|
+
ENUM = {
|
|
18
|
+
'' => 'Not yet defined',
|
|
19
|
+
'end-of-month' => 'End of month',
|
|
20
|
+
'due-date' => 'Due on a specific date',
|
|
21
|
+
'deferred' => 'Deferred until after the due date',
|
|
22
|
+
'proximo' => 'Month after the present',
|
|
23
|
+
'instant' => 'On receipt of invoice',
|
|
24
|
+
'elective' => 'Chosen by the buyer',
|
|
25
|
+
'pending' => 'Seller to advise buyer in separate transaction',
|
|
26
|
+
'advance' => 'Payment made in advance',
|
|
27
|
+
'delivery' => 'Payment on Delivery'
|
|
28
|
+
}.freeze
|
|
29
|
+
|
|
30
|
+
attribute :_value, GOBL::Types::String.enum(*ENUM.keys)
|
|
31
|
+
private :_value
|
|
32
|
+
|
|
33
|
+
# Creates a new object from a GOBL value
|
|
34
|
+
#
|
|
35
|
+
# @param data [String] the GOBL value
|
|
36
|
+
#
|
|
37
|
+
# @return [TermKey] the object created from the given data
|
|
38
|
+
def self.from_gobl!(data)
|
|
39
|
+
new(_value: data)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Returns a GOBL value representing the current object
|
|
43
|
+
#
|
|
44
|
+
# @return [String] the GOBL value that represents the current object
|
|
45
|
+
def to_gobl
|
|
46
|
+
_value
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Returns a {TermKey} that corresponds to a given object. The object can be a
|
|
50
|
+
# `Symbol`, a `String` or anything coercible into one (via `#to_s`).
|
|
51
|
+
#
|
|
52
|
+
# @param object [Symbol, String, #to_s] the value of the object.
|
|
53
|
+
#
|
|
54
|
+
# @return [TermKey] the object corresponding to the given value.
|
|
55
|
+
#
|
|
56
|
+
# @example Instantiating from a symbol
|
|
57
|
+
# term_key = GOBL::Pay::TermKey.new(:)
|
|
58
|
+
#
|
|
59
|
+
# @example Instantiating from a string
|
|
60
|
+
# term_key = GOBL::Pay::TermKey.new('')
|
|
61
|
+
def self.new(object)
|
|
62
|
+
case object
|
|
63
|
+
when Hash, self # internal use, not to be used in public calls
|
|
64
|
+
super
|
|
65
|
+
when Symbol
|
|
66
|
+
new find_by_sym(object)
|
|
67
|
+
else
|
|
68
|
+
super _value: object.to_s
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Returns the string representation of the current object
|
|
73
|
+
#
|
|
74
|
+
# @return [String] the string representation of the current object
|
|
75
|
+
def to_s
|
|
76
|
+
_value.to_s
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Returns the symbol representation of the current object
|
|
80
|
+
#
|
|
81
|
+
# @return [Symbol] the symbol representation of the current object
|
|
82
|
+
def to_sym
|
|
83
|
+
to_s.parameterize.underscore.to_sym
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Returns whether the current object is equivalent to a given one. In addition
|
|
87
|
+
# to {TermKey} objects, the current object can be compared to a `Symbol`, a
|
|
88
|
+
# `String` or anything coercible into one (via `#to_s`)
|
|
89
|
+
#
|
|
90
|
+
# @param other [TermKey, Symbol, String, #to_s] the other object to compare to
|
|
91
|
+
#
|
|
92
|
+
# @return [Boolean] `true` if the objects are equivalent, `false` otherwise
|
|
93
|
+
#
|
|
94
|
+
# @example Comparing to another {TermKey} object
|
|
95
|
+
# term_key = GOBL::Pay::TermKey.new('')
|
|
96
|
+
# term_key == GOBL::Pay::TermKey.new('') #=> true
|
|
97
|
+
# term_key == GOBL::Pay::TermKey.new('end-of-month') #=> false
|
|
98
|
+
#
|
|
99
|
+
# @example Comparing to a string
|
|
100
|
+
# term_key = GOBL::Pay::TermKey.new('')
|
|
101
|
+
# term_key == '' #=> true
|
|
102
|
+
# term_key == 'end-of-month' #=> false
|
|
103
|
+
#
|
|
104
|
+
# @example Comparing to a symbol
|
|
105
|
+
# term_key = GOBL::Pay::TermKey.new('')
|
|
106
|
+
# term_key == : #=> true
|
|
107
|
+
# term_key == :end_of_month #=> false
|
|
108
|
+
def ==(other)
|
|
109
|
+
case other
|
|
110
|
+
when self.class
|
|
111
|
+
super
|
|
112
|
+
when Symbol
|
|
113
|
+
to_sym == other
|
|
114
|
+
else
|
|
115
|
+
to_s == other.to_s
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Returns an array with all the enumerated objects of this type
|
|
120
|
+
#
|
|
121
|
+
# @return [Array<TermKey>] the array of enumerated objects
|
|
122
|
+
def self.all
|
|
123
|
+
ENUM.keys.map { |key| new(key) }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# @api private
|
|
127
|
+
def self.find_by_sym(sym)
|
|
128
|
+
all.find { |object| object.to_sym == sym }
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# @api private
|
|
132
|
+
def self.find_by_inquirer(method_name)
|
|
133
|
+
method_name =~ /(.+)\?$/ && find_by_sym(Regexp.last_match(1).to_sym)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Returns the description of the current object
|
|
137
|
+
#
|
|
138
|
+
# @return [String] the description of the current object
|
|
139
|
+
def description
|
|
140
|
+
ENUM.fetch(_value, _value)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# @api private
|
|
144
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
145
|
+
self.class.find_by_inquirer(method_name) || super
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Enables dynamic value inquirers like `TermKey#?` for
|
|
149
|
+
# each of the declared enum values (see {ENUM}). Each inquirer returns a
|
|
150
|
+
# `Boolean` denoting whether the value equals the enquired value (`true`) or
|
|
151
|
+
# not (`false`)
|
|
152
|
+
#
|
|
153
|
+
# @example
|
|
154
|
+
# term_key = GOBL::Pay::TermKey.new('')
|
|
155
|
+
# term_key.? # => true
|
|
156
|
+
# term_key.end_of_month? # => false
|
|
157
|
+
def method_missing(method_name, *args, &block)
|
|
158
|
+
if value = self.class.find_by_inquirer(method_name)
|
|
159
|
+
self == value
|
|
160
|
+
else
|
|
161
|
+
super
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
## DO NOT EDIT - This file was generated automatically.
|
|
5
|
+
##
|
|
6
|
+
## Generated with GOBL v0.30.4
|
|
7
|
+
##
|
|
8
|
+
|
|
9
|
+
module GOBL
|
|
10
|
+
module Pay
|
|
11
|
+
# Terms defines when we expect the customer to pay, or have paid, for the contents of the document.
|
|
12
|
+
class Terms < GOBL::Struct
|
|
13
|
+
# The Schema ID of the GOBL Terms structure
|
|
14
|
+
SCHEMA_ID = 'https://gobl.org/draft-0/pay/terms'
|
|
15
|
+
|
|
16
|
+
# @!attribute [r] key
|
|
17
|
+
# Type of terms to be applied.
|
|
18
|
+
# @return [TermKey]
|
|
19
|
+
attribute :key, TermKey
|
|
20
|
+
|
|
21
|
+
# @!attribute [r] detail
|
|
22
|
+
# Text detail of the chosen payment terms.
|
|
23
|
+
# @return [String]
|
|
24
|
+
attribute? :detail, GOBL::Types::String.optional
|
|
25
|
+
|
|
26
|
+
# @!attribute [r] due_dates
|
|
27
|
+
# Set of dates for agreed payments.
|
|
28
|
+
# @return [Array<DueDate>]
|
|
29
|
+
attribute? :due_dates, GOBL::Types::Array.of(DueDate).optional
|
|
30
|
+
|
|
31
|
+
# @!attribute [r] notes
|
|
32
|
+
# Description of the conditions for payment.
|
|
33
|
+
# @return [String]
|
|
34
|
+
attribute? :notes, GOBL::Types::String.optional
|
|
35
|
+
|
|
36
|
+
# Creates a new object from a hash of GOBL data
|
|
37
|
+
#
|
|
38
|
+
# @param data [Hash] a hash of GOBL data
|
|
39
|
+
#
|
|
40
|
+
# @return [Terms] the object created from the given data
|
|
41
|
+
def self.from_gobl!(data)
|
|
42
|
+
data = GOBL::Types::Hash[data]
|
|
43
|
+
|
|
44
|
+
new(
|
|
45
|
+
key: TermKey.from_gobl!(data['key']),
|
|
46
|
+
detail: data['detail'],
|
|
47
|
+
due_dates: data['due_dates']&.map { |item| DueDate.from_gobl!(item) },
|
|
48
|
+
notes: data['notes']
|
|
49
|
+
)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Returns a hash of GOBL data representing the current object
|
|
53
|
+
#
|
|
54
|
+
# @return [Hash] the array of GOBL data that represents the current object
|
|
55
|
+
def to_gobl
|
|
56
|
+
{
|
|
57
|
+
'key' => attributes[:key]&.to_gobl,
|
|
58
|
+
'detail' => attributes[:detail],
|
|
59
|
+
'due_dates' => attributes[:due_dates]&.map { |item| item&.to_gobl },
|
|
60
|
+
'notes' => attributes[:notes]
|
|
61
|
+
}.compact
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# @!method self.new(attrs)
|
|
65
|
+
#
|
|
66
|
+
# Returns a {Terms} object from a given hash of attributes. Nested
|
|
67
|
+
# attributes are supported: the constructor will instantiate the proper GOBL
|
|
68
|
+
# objects when nested hashes or arrays are given as part of the `attrs`
|
|
69
|
+
# parameter.
|
|
70
|
+
#
|
|
71
|
+
# The `new` method will only allow to create a new object if all attributes
|
|
72
|
+
# marked as mandatory and not calculated in the JSON schema are provided.
|
|
73
|
+
#
|
|
74
|
+
# @param attrs [Hash] the hash of attributes
|
|
75
|
+
#
|
|
76
|
+
# @return [Terms] the object corresponding to the given input
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
data/lib/gobl/stamp.rb
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
## DO NOT EDIT - This file was generated automatically.
|
|
5
|
+
##
|
|
6
|
+
## Generated with GOBL v0.30.4
|
|
7
|
+
##
|
|
8
|
+
|
|
9
|
+
module GOBL
|
|
10
|
+
# Stamp defines an official seal of approval from a third party like a governmental agency or intermediary and should thus be included in any official envelopes.
|
|
11
|
+
class Stamp < GOBL::Struct
|
|
12
|
+
# The Schema ID of the GOBL Stamp structure
|
|
13
|
+
SCHEMA_ID = 'https://gobl.org/draft-0/envelope#/$defs/Stamp'
|
|
14
|
+
|
|
15
|
+
# @!attribute [r] prv
|
|
16
|
+
# Identity of the agency used to create the stamp usually defined by each region.
|
|
17
|
+
# @return [GOBL::Org::Key]
|
|
18
|
+
attribute :prv, GOBL::Org::Key
|
|
19
|
+
|
|
20
|
+
# @!attribute [r] val
|
|
21
|
+
# The serialized stamp value generated for or by the external agency
|
|
22
|
+
# @return [String]
|
|
23
|
+
attribute :val, GOBL::Types::String
|
|
24
|
+
|
|
25
|
+
# Creates a new object from a hash of GOBL data
|
|
26
|
+
#
|
|
27
|
+
# @param data [Hash] a hash of GOBL data
|
|
28
|
+
#
|
|
29
|
+
# @return [Stamp] the object created from the given data
|
|
30
|
+
def self.from_gobl!(data)
|
|
31
|
+
data = GOBL::Types::Hash[data]
|
|
32
|
+
|
|
33
|
+
new(
|
|
34
|
+
prv: GOBL::Org::Key.from_gobl!(data['prv']),
|
|
35
|
+
val: data['val']
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Returns a hash of GOBL data representing the current object
|
|
40
|
+
#
|
|
41
|
+
# @return [Hash] the array of GOBL data that represents the current object
|
|
42
|
+
def to_gobl
|
|
43
|
+
{
|
|
44
|
+
'prv' => attributes[:prv]&.to_gobl,
|
|
45
|
+
'val' => attributes[:val]
|
|
46
|
+
}.compact
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# @!method self.new(attrs)
|
|
50
|
+
#
|
|
51
|
+
# Returns a {Stamp} object from a given hash of attributes. Nested
|
|
52
|
+
# attributes are supported: the constructor will instantiate the proper GOBL
|
|
53
|
+
# objects when nested hashes or arrays are given as part of the `attrs`
|
|
54
|
+
# parameter.
|
|
55
|
+
#
|
|
56
|
+
# The `new` method will only allow to create a new object if all attributes
|
|
57
|
+
# marked as mandatory and not calculated in the JSON schema are provided.
|
|
58
|
+
#
|
|
59
|
+
# @param attrs [Hash] the hash of attributes
|
|
60
|
+
#
|
|
61
|
+
# @return [Stamp] the object corresponding to the given input
|
|
62
|
+
end
|
|
63
|
+
end
|
data/lib/gobl/struct.rb
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GOBL
|
|
4
|
+
# Base class for any GOBL structure
|
|
5
|
+
class Struct < Dry::Struct
|
|
6
|
+
# Returns a new GOBL struct from a hash of GOBL data. The type of the returned struct
|
|
7
|
+
# is determined from the `$schema` attribute.
|
|
8
|
+
#
|
|
9
|
+
# This method is usually overwritten at sub-class level, where the `$schema` attribute
|
|
10
|
+
# isn't necessary since the type is determined by the sub-class itself.
|
|
11
|
+
#
|
|
12
|
+
# @param data [Hash] the hash of GOBL data
|
|
13
|
+
#
|
|
14
|
+
# @return [GOBL::Struct] the created GOBL struct
|
|
15
|
+
def self.from_gobl!(data)
|
|
16
|
+
raise ArgumentError, 'Schema not present in the given data' unless data&.key?('$schema')
|
|
17
|
+
|
|
18
|
+
schema = GOBL::ID.new(data['$schema'])
|
|
19
|
+
|
|
20
|
+
# This could become more sophisticated in the future. For the moment, any schema not
|
|
21
|
+
# being an envelope is considered to be a document as these are the only two structures
|
|
22
|
+
# that are required to specify its schema.
|
|
23
|
+
if schema.name == 'envelope'
|
|
24
|
+
GOBL::Envelope.from_gobl! data
|
|
25
|
+
else
|
|
26
|
+
GOBL::Document.from_gobl! data
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Deserializes a GOBL struct from a JSON string
|
|
31
|
+
#
|
|
32
|
+
# @param json [String] the JSON string representing the GOBL struct
|
|
33
|
+
#
|
|
34
|
+
# @return [GOBL::Struct] the deserialized GOBL struct
|
|
35
|
+
def self.from_json!(json)
|
|
36
|
+
from_gobl!(JSON.parse(json))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Serializes a GOBL struct into a JSON string
|
|
40
|
+
#
|
|
41
|
+
# @param options [#to_h] a Hash-like object to pass to `JSON.generate`
|
|
42
|
+
#
|
|
43
|
+
# @return [GOBL::Struct] the JSON string representing the GOBL struct
|
|
44
|
+
def to_json(options = nil)
|
|
45
|
+
JSON.generate(to_gobl, options)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|