gobl 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ext/hashme.rb +28 -0
- data/lib/gobl/bill/advances.rb +1 -77
- data/lib/gobl/bill/charge.rb +11 -65
- data/lib/gobl/bill/delivery.rb +5 -47
- data/lib/gobl/bill/discount.rb +11 -65
- data/lib/gobl/bill/exchange_rates.rb +1 -77
- data/lib/gobl/bill/invoice.rb +28 -104
- data/lib/gobl/bill/invoice_type.rb +3 -134
- data/lib/gobl/bill/line.rb +13 -65
- data/lib/gobl/bill/line_charge.rb +5 -47
- data/lib/gobl/bill/line_discount.rb +5 -47
- data/lib/gobl/bill/ordering.rb +2 -38
- data/lib/gobl/bill/outlay.rb +11 -59
- data/lib/gobl/bill/payment.rb +5 -47
- data/lib/gobl/bill/preceding.rb +12 -62
- data/lib/gobl/bill/scheme_keys.rb +1 -77
- data/lib/gobl/bill/tax.rb +4 -44
- data/lib/gobl/bill/totals.rb +17 -71
- data/lib/gobl/cal/date.rb +1 -90
- data/lib/gobl/cal/period.rb +5 -41
- data/lib/gobl/currency/code.rb +3 -134
- data/lib/gobl/currency/exchange_rate.rb +5 -41
- data/lib/gobl/document.rb +1 -58
- data/lib/gobl/dsig/digest.rb +5 -41
- data/lib/gobl/dsig/signature.rb +1 -90
- data/lib/gobl/enum.rb +81 -0
- data/lib/gobl/envelope.rb +9 -48
- data/lib/gobl/header.rb +10 -56
- data/lib/gobl/i18n/string.rb +1 -58
- data/lib/gobl/l10n/code.rb +1 -90
- data/lib/gobl/l10n/country_code.rb +3 -134
- data/lib/gobl/map.rb +62 -0
- data/lib/gobl/note/message.rb +5 -44
- data/lib/gobl/num/amount.rb +6 -35
- data/lib/gobl/object.rb +21 -0
- data/lib/gobl/operations.rb +3 -3
- data/lib/gobl/org/address.rb +18 -80
- data/lib/gobl/org/code.rb +1 -90
- data/lib/gobl/org/coordinates.rb +5 -47
- data/lib/gobl/org/email.rb +6 -47
- data/lib/gobl/org/inbox.rb +8 -50
- data/lib/gobl/org/item.rb +13 -65
- data/lib/gobl/org/item_code.rb +4 -41
- data/lib/gobl/org/key.rb +1 -90
- data/lib/gobl/org/meta.rb +1 -58
- data/lib/gobl/org/name.rb +12 -62
- data/lib/gobl/org/note.rb +6 -47
- data/lib/gobl/org/note_key.rb +3 -134
- data/lib/gobl/org/party.rb +14 -71
- data/lib/gobl/org/person.rb +9 -56
- data/lib/gobl/org/registration.rb +9 -59
- data/lib/gobl/org/source_key.rb +3 -134
- data/lib/gobl/org/tax_identity.rb +8 -53
- data/lib/gobl/org/telephone.rb +5 -44
- data/lib/gobl/org/unit.rb +1 -136
- data/lib/gobl/pay/advance.rb +11 -59
- data/lib/gobl/pay/card.rb +5 -41
- data/lib/gobl/pay/credit_transfer.rb +6 -50
- data/lib/gobl/pay/direct_debit.rb +4 -44
- data/lib/gobl/pay/due_date.rb +8 -50
- data/lib/gobl/pay/instructions.rb +11 -62
- data/lib/gobl/pay/method_key.rb +3 -134
- data/lib/gobl/pay/online.rb +4 -41
- data/lib/gobl/pay/term_key.rb +3 -134
- data/lib/gobl/pay/terms.rb +6 -47
- data/lib/gobl/stamp.rb +5 -41
- data/lib/gobl/struct.rb +15 -15
- data/lib/gobl/tax/category.rb +9 -50
- data/lib/gobl/tax/category_total.rb +11 -53
- data/lib/gobl/tax/combo.rb +6 -47
- data/lib/gobl/tax/localities.rb +1 -77
- data/lib/gobl/tax/locality.rb +6 -44
- data/lib/gobl/tax/rate.rb +8 -47
- data/lib/gobl/tax/rate_total.rb +9 -50
- data/lib/gobl/tax/rate_total_surcharge.rb +5 -41
- data/lib/gobl/tax/rate_value.rb +6 -47
- data/lib/gobl/tax/region.rb +12 -56
- data/lib/gobl/tax/scheme.rb +8 -50
- data/lib/gobl/tax/schemes.rb +1 -77
- data/lib/gobl/tax/set.rb +1 -77
- data/lib/gobl/tax/total.rb +4 -41
- data/lib/gobl/uuid/uuid.rb +1 -90
- data/lib/gobl/value.rb +58 -0
- data/lib/gobl/version.rb +1 -1
- data/lib/gobl.rb +3 -1
- data/lib/gobl_extensions/document_helper.rb +3 -3
- data/lib/gobl_extensions/envelope_helper.rb +5 -0
- data/lib/gobl_extensions/i18n/value_keys_helper.rb +3 -3
- data/lib/gobl_extensions/tax/region_helper.rb +3 -9
- metadata +11 -36
- data/home/cavalle/workspace/invopop/gobl.ruby/gobl.gemspec +0 -30
- data/lib/gobl/types.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e52ec878de6b32774a12c296cd33c914373d6af02f8aa60f02320876b124f47f
|
4
|
+
data.tar.gz: 8a610c8a3758bcd87d31d9062b46921ae56c91f834259430a3befab7f4c04551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d9feadf8a8233343c9a97103991ccd7bc9a9312c66f904dcaf29b60915de5dc73d604c2b11021a18ef11000b5c2d525c2af3c4f9d325fe8d882cf7c881d9169
|
7
|
+
data.tar.gz: 07a08ffd6bcc9a6fe5c8419d9869e8c1e046348b3226971dd38057d2728c704dd3e4e70a3d18335d4dd0a74c28db84264add27d888d9373ad0216249b13e9e56
|
data/lib/ext/hashme.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
raise 'The `hashme` library version has changed. Review if this extension still applies' if Hashme::VERSION != '0.2.6'
|
4
|
+
|
5
|
+
# Temporary extensions for the `hashme` gem. To be removed when the library supports them.
|
6
|
+
# @api private
|
7
|
+
module Hashme
|
8
|
+
# Adds an URI helper class to the Hashme namespace so that properties referencing them
|
9
|
+
# typecast to URI objects in Ruby standard library.
|
10
|
+
class URI
|
11
|
+
def self.new(value)
|
12
|
+
URI(value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# TrueClass typecasts to a boolean in Hashme. We alias it to `Boolean` for clarity
|
17
|
+
Boolean = TrueClass
|
18
|
+
|
19
|
+
class CastedArray
|
20
|
+
# Provides access to the whole Enumerable set of methods
|
21
|
+
include Enumerable
|
22
|
+
|
23
|
+
# Fixes equality between CastedArray objects
|
24
|
+
def ==(other)
|
25
|
+
@_array == other.to_a
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/gobl/bill/advances.rb
CHANGED
@@ -9,82 +9,6 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Bill
|
11
11
|
# Advances contains an array of advance objects.
|
12
|
-
|
13
|
-
extend Forwardable
|
14
|
-
include Enumerable
|
15
|
-
|
16
|
-
# The Schema ID of the GOBL Advances structure
|
17
|
-
SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Advances'
|
18
|
-
|
19
|
-
attribute :_ary, GOBL::Types::Array.of(GOBL::Pay::Advance)
|
20
|
-
|
21
|
-
# @!method [](*args)
|
22
|
-
# Returns elements from the array
|
23
|
-
# @overload [](index)
|
24
|
-
# Returns the element in a specific position
|
25
|
-
# @param index [Integer] the position of the object
|
26
|
-
# @return [GOBL::Pay::Advance] the element in the `index` position
|
27
|
-
# @overload [](start, length)
|
28
|
-
# Returns all the elements within a range of positions
|
29
|
-
# @param start [Integer] start position of the range
|
30
|
-
# @param length [Integer] length of the range
|
31
|
-
# @return [Array<GOBL::Pay::Advance>] the elements in the range
|
32
|
-
# @overload [](range)
|
33
|
-
# Returns all the elements within a range
|
34
|
-
# @param range [Range] start and end positions of the range
|
35
|
-
# @return [Array<GOBL::Pay::Advance>] the elements in the range
|
36
|
-
#
|
37
|
-
# @!method each
|
38
|
-
# Iterates over the array elements
|
39
|
-
# @overload each(&block)
|
40
|
-
# Calls the given block with each element in the array
|
41
|
-
# @yield [element] element of the array
|
42
|
-
# @return [self] the object itself
|
43
|
-
# @overload each
|
44
|
-
# Returns an Enumerator that iterates over the array elements
|
45
|
-
# @return [Enumerator] the enumerator of the array elements
|
46
|
-
#
|
47
|
-
# @!method empty?
|
48
|
-
# Returns `true` if the number of elements in the array is zero, `false` otherwise.
|
49
|
-
# @return [Boolean] whether the array is empty or not
|
50
|
-
#
|
51
|
-
# @!method length
|
52
|
-
# Returns the number of elements in the array
|
53
|
-
# @return [Integer] the number of elements in the array
|
54
|
-
def_delegators :_ary, :[], :each, :empty?, :length
|
55
|
-
|
56
|
-
# Creates a new object from an array of GOBL data
|
57
|
-
#
|
58
|
-
# @param data [Array] an array of GOBL data
|
59
|
-
#
|
60
|
-
# @return [Advances] the object created from the given data
|
61
|
-
def self.from_gobl!(data)
|
62
|
-
new(_ary: data&.map { |item| GOBL::Pay::Advance.from_gobl!(item) })
|
63
|
-
end
|
64
|
-
|
65
|
-
# Returns an array of GOBL data representing the current object
|
66
|
-
#
|
67
|
-
# @return [Array<Hash>] the array of GOBL data that represents the current object
|
68
|
-
def to_gobl
|
69
|
-
_ary.map(&:to_gobl)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Returns a {Advances} object from a given array of structs. The array may
|
73
|
-
# contain {GOBL::Pay::Advance} objects or hashes. If hashes are provided, the constructor
|
74
|
-
# will call `GOBL::Pay::Advance#new` to generate the objects that will be part of the
|
75
|
-
# returned {Advances} object
|
76
|
-
#
|
77
|
-
# @param object [Array<GOBL::Pay::Advance, Hash>] the array containing the structs
|
78
|
-
#
|
79
|
-
# @return [Advances] the object corresponding to the given input
|
80
|
-
def self.new(object)
|
81
|
-
case object
|
82
|
-
when Array
|
83
|
-
super _ary: object
|
84
|
-
else # internal use, not to be used in public calls
|
85
|
-
super
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
12
|
+
Advances = [GOBL::Pay::Advance] # rubocop:disable Naming/ConstantName, Style/MutableConstant
|
89
13
|
end
|
90
14
|
end
|
data/lib/gobl/bill/charge.rb
CHANGED
@@ -9,113 +9,59 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Bill
|
11
11
|
# Charge represents a surchange applied to the complete document independent from the individual lines.
|
12
|
-
class Charge < GOBL::
|
12
|
+
class Charge < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Charge structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Charge'
|
15
15
|
|
16
16
|
# @!attribute [r] uuid
|
17
17
|
# Unique identifying for the discount entry
|
18
18
|
# @return [GOBL::UUID::UUID]
|
19
|
-
|
19
|
+
property :uuid, GOBL::UUID::UUID
|
20
20
|
|
21
21
|
# @!attribute [r] i
|
22
22
|
# Line number inside the list of discounts (calculated).
|
23
23
|
# @return [Integer]
|
24
|
-
|
24
|
+
property :i, Integer
|
25
25
|
|
26
26
|
# @!attribute [r] ref
|
27
27
|
# Code to used to refer to the this charge
|
28
28
|
# @return [String]
|
29
|
-
|
29
|
+
property :ref, String
|
30
30
|
|
31
31
|
# @!attribute [r] base
|
32
32
|
# Base represents the value used as a base for percent calculations. If not already provided, we'll take the invoices sum before discounts.
|
33
33
|
# @return [GOBL::Num::Amount]
|
34
|
-
|
34
|
+
property :base, GOBL::Num::Amount
|
35
35
|
|
36
36
|
# @!attribute [r] percent
|
37
37
|
# Percentage to apply to the invoice's Sum
|
38
38
|
# @return [GOBL::Num::Percentage]
|
39
|
-
|
39
|
+
property :percent, GOBL::Num::Percentage
|
40
40
|
|
41
41
|
# @!attribute [r] amount
|
42
42
|
# Amount to apply (calculated if percent present)
|
43
43
|
# @return [GOBL::Num::Amount]
|
44
|
-
|
44
|
+
property :amount, GOBL::Num::Amount
|
45
45
|
|
46
46
|
# @!attribute [r] taxes
|
47
47
|
# List of taxes to apply to the charge
|
48
48
|
# @return [GOBL::Tax::Set]
|
49
|
-
|
49
|
+
property :taxes, GOBL::Tax::Set
|
50
50
|
|
51
51
|
# @!attribute [r] code
|
52
52
|
# Code for why was this charge applied?
|
53
53
|
# @return [String]
|
54
|
-
|
54
|
+
property :code, String
|
55
55
|
|
56
56
|
# @!attribute [r] reason
|
57
57
|
# Text description as to why the charge was applied
|
58
58
|
# @return [String]
|
59
|
-
|
59
|
+
property :reason, String
|
60
60
|
|
61
61
|
# @!attribute [r] meta
|
62
62
|
# Additional semi-structured information.
|
63
63
|
# @return [GOBL::Org::Meta]
|
64
|
-
|
65
|
-
|
66
|
-
# Creates a new object from a hash of GOBL data
|
67
|
-
#
|
68
|
-
# @param data [Hash] a hash of GOBL data
|
69
|
-
#
|
70
|
-
# @return [Charge] the object created from the given data
|
71
|
-
def self.from_gobl!(data)
|
72
|
-
data = GOBL::Types::Hash[data]
|
73
|
-
|
74
|
-
new(
|
75
|
-
uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
|
76
|
-
i: data['i'],
|
77
|
-
ref: data['ref'],
|
78
|
-
base: data['base'] || nil,
|
79
|
-
percent: data['percent'] || nil,
|
80
|
-
amount: data['amount'] || nil,
|
81
|
-
taxes: data['taxes'] ? GOBL::Tax::Set.from_gobl!(data['taxes']) : nil,
|
82
|
-
code: data['code'],
|
83
|
-
reason: data['reason'],
|
84
|
-
meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
|
85
|
-
)
|
86
|
-
end
|
87
|
-
|
88
|
-
# Returns a hash of GOBL data representing the current object
|
89
|
-
#
|
90
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
91
|
-
def to_gobl
|
92
|
-
{
|
93
|
-
'uuid' => attributes[:uuid]&.to_gobl,
|
94
|
-
'i' => attributes[:i],
|
95
|
-
'ref' => attributes[:ref],
|
96
|
-
'base' => attributes[:base]&.to_gobl,
|
97
|
-
'percent' => attributes[:percent]&.to_gobl,
|
98
|
-
'amount' => attributes[:amount]&.to_gobl,
|
99
|
-
'taxes' => attributes[:taxes]&.to_gobl,
|
100
|
-
'code' => attributes[:code],
|
101
|
-
'reason' => attributes[:reason],
|
102
|
-
'meta' => attributes[:meta]&.to_gobl
|
103
|
-
}.compact
|
104
|
-
end
|
105
|
-
|
106
|
-
# @!method self.new(attrs)
|
107
|
-
#
|
108
|
-
# Returns a {Charge} object from a given hash of attributes. Nested
|
109
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
110
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
111
|
-
# parameter.
|
112
|
-
#
|
113
|
-
# The `new` method will only allow to create a new object if all attributes
|
114
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
115
|
-
#
|
116
|
-
# @param attrs [Hash] the hash of attributes
|
117
|
-
#
|
118
|
-
# @return [Charge] the object corresponding to the given input
|
64
|
+
property :meta, GOBL::Org::Meta
|
119
65
|
end
|
120
66
|
end
|
121
67
|
end
|
data/lib/gobl/bill/delivery.rb
CHANGED
@@ -9,71 +9,29 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Bill
|
11
11
|
# Delivery covers the details of the destination for the products described in the invoice body.
|
12
|
-
class Delivery < GOBL::
|
12
|
+
class Delivery < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Delivery structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Delivery'
|
15
15
|
|
16
16
|
# @!attribute [r] receiver
|
17
17
|
# The party who will receive delivery of the goods defined in the invoice and is not responsible for taxes.
|
18
18
|
# @return [GOBL::Org::Party]
|
19
|
-
|
19
|
+
property :receiver, GOBL::Org::Party
|
20
20
|
|
21
21
|
# @!attribute [r] date
|
22
22
|
# When the goods should be expected
|
23
23
|
# @return [GOBL::Cal::Date]
|
24
|
-
|
24
|
+
property :date, GOBL::Cal::Date
|
25
25
|
|
26
26
|
# @!attribute [r] start_date
|
27
27
|
# Start of a n invoicing or delivery period
|
28
28
|
# @return [GOBL::Cal::Date]
|
29
|
-
|
29
|
+
property :start_date, GOBL::Cal::Date
|
30
30
|
|
31
31
|
# @!attribute [r] end_date
|
32
32
|
# End of a n invoicing or delivery period
|
33
33
|
# @return [GOBL::Cal::Date]
|
34
|
-
|
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 [Delivery] the object created from the given data
|
41
|
-
def self.from_gobl!(data)
|
42
|
-
data = GOBL::Types::Hash[data]
|
43
|
-
|
44
|
-
new(
|
45
|
-
receiver: data['receiver'] ? GOBL::Org::Party.from_gobl!(data['receiver']) : nil,
|
46
|
-
date: data['date'] ? GOBL::Cal::Date.from_gobl!(data['date']) : nil,
|
47
|
-
start_date: data['start_date'] ? GOBL::Cal::Date.from_gobl!(data['start_date']) : nil,
|
48
|
-
end_date: data['end_date'] ? GOBL::Cal::Date.from_gobl!(data['end_date']) : nil
|
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
|
-
'receiver' => attributes[:receiver]&.to_gobl,
|
58
|
-
'date' => attributes[:date]&.to_gobl,
|
59
|
-
'start_date' => attributes[:start_date]&.to_gobl,
|
60
|
-
'end_date' => attributes[:end_date]&.to_gobl
|
61
|
-
}.compact
|
62
|
-
end
|
63
|
-
|
64
|
-
# @!method self.new(attrs)
|
65
|
-
#
|
66
|
-
# Returns a {Delivery} 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 [Delivery] the object corresponding to the given input
|
34
|
+
property :end_date, GOBL::Cal::Date
|
77
35
|
end
|
78
36
|
end
|
79
37
|
end
|
data/lib/gobl/bill/discount.rb
CHANGED
@@ -9,113 +9,59 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Bill
|
11
11
|
# Discount represents an allowance applied to the complete document independent from the individual lines.
|
12
|
-
class Discount < GOBL::
|
12
|
+
class Discount < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Discount structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Discount'
|
15
15
|
|
16
16
|
# @!attribute [r] uuid
|
17
17
|
# Unique identifying for the discount entry
|
18
18
|
# @return [GOBL::UUID::UUID]
|
19
|
-
|
19
|
+
property :uuid, GOBL::UUID::UUID
|
20
20
|
|
21
21
|
# @!attribute [r] i
|
22
22
|
# Line number inside the list of discounts (calculated)
|
23
23
|
# @return [Integer]
|
24
|
-
|
24
|
+
property :i, Integer
|
25
25
|
|
26
26
|
# @!attribute [r] ref
|
27
27
|
# Reference or ID for this Discount
|
28
28
|
# @return [String]
|
29
|
-
|
29
|
+
property :ref, String
|
30
30
|
|
31
31
|
# @!attribute [r] base
|
32
32
|
# Base represents the value used as a base for percent calculations. If not already provided, we'll take the invoices sum.
|
33
33
|
# @return [GOBL::Num::Amount]
|
34
|
-
|
34
|
+
property :base, GOBL::Num::Amount
|
35
35
|
|
36
36
|
# @!attribute [r] percent
|
37
37
|
# Percentage to apply to the invoice's Sum.
|
38
38
|
# @return [GOBL::Num::Percentage]
|
39
|
-
|
39
|
+
property :percent, GOBL::Num::Percentage
|
40
40
|
|
41
41
|
# @!attribute [r] amount
|
42
42
|
# Amount to apply (calculated if percent present).
|
43
43
|
# @return [GOBL::Num::Amount]
|
44
|
-
|
44
|
+
property :amount, GOBL::Num::Amount
|
45
45
|
|
46
46
|
# @!attribute [r] taxes
|
47
47
|
# List of taxes to apply to the discount
|
48
48
|
# @return [GOBL::Tax::Set]
|
49
|
-
|
49
|
+
property :taxes, GOBL::Tax::Set
|
50
50
|
|
51
51
|
# @!attribute [r] code
|
52
52
|
# Code for the reason this discount applied
|
53
53
|
# @return [String]
|
54
|
-
|
54
|
+
property :code, String
|
55
55
|
|
56
56
|
# @!attribute [r] reason
|
57
57
|
# Text description as to why the discount was applied
|
58
58
|
# @return [String]
|
59
|
-
|
59
|
+
property :reason, String
|
60
60
|
|
61
61
|
# @!attribute [r] meta
|
62
62
|
# Additional semi-structured information.
|
63
63
|
# @return [GOBL::Org::Meta]
|
64
|
-
|
65
|
-
|
66
|
-
# Creates a new object from a hash of GOBL data
|
67
|
-
#
|
68
|
-
# @param data [Hash] a hash of GOBL data
|
69
|
-
#
|
70
|
-
# @return [Discount] the object created from the given data
|
71
|
-
def self.from_gobl!(data)
|
72
|
-
data = GOBL::Types::Hash[data]
|
73
|
-
|
74
|
-
new(
|
75
|
-
uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
|
76
|
-
i: data['i'],
|
77
|
-
ref: data['ref'],
|
78
|
-
base: data['base'] || nil,
|
79
|
-
percent: data['percent'] || nil,
|
80
|
-
amount: data['amount'] || nil,
|
81
|
-
taxes: data['taxes'] ? GOBL::Tax::Set.from_gobl!(data['taxes']) : nil,
|
82
|
-
code: data['code'],
|
83
|
-
reason: data['reason'],
|
84
|
-
meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
|
85
|
-
)
|
86
|
-
end
|
87
|
-
|
88
|
-
# Returns a hash of GOBL data representing the current object
|
89
|
-
#
|
90
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
91
|
-
def to_gobl
|
92
|
-
{
|
93
|
-
'uuid' => attributes[:uuid]&.to_gobl,
|
94
|
-
'i' => attributes[:i],
|
95
|
-
'ref' => attributes[:ref],
|
96
|
-
'base' => attributes[:base]&.to_gobl,
|
97
|
-
'percent' => attributes[:percent]&.to_gobl,
|
98
|
-
'amount' => attributes[:amount]&.to_gobl,
|
99
|
-
'taxes' => attributes[:taxes]&.to_gobl,
|
100
|
-
'code' => attributes[:code],
|
101
|
-
'reason' => attributes[:reason],
|
102
|
-
'meta' => attributes[:meta]&.to_gobl
|
103
|
-
}.compact
|
104
|
-
end
|
105
|
-
|
106
|
-
# @!method self.new(attrs)
|
107
|
-
#
|
108
|
-
# Returns a {Discount} object from a given hash of attributes. Nested
|
109
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
110
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
111
|
-
# parameter.
|
112
|
-
#
|
113
|
-
# The `new` method will only allow to create a new object if all attributes
|
114
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
115
|
-
#
|
116
|
-
# @param attrs [Hash] the hash of attributes
|
117
|
-
#
|
118
|
-
# @return [Discount] the object corresponding to the given input
|
64
|
+
property :meta, GOBL::Org::Meta
|
119
65
|
end
|
120
66
|
end
|
121
67
|
end
|
@@ -9,82 +9,6 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Bill
|
11
11
|
# ExchangeRates represents an array of currency exchange rates.
|
12
|
-
|
13
|
-
extend Forwardable
|
14
|
-
include Enumerable
|
15
|
-
|
16
|
-
# The Schema ID of the GOBL ExchangeRates structure
|
17
|
-
SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/ExchangeRates'
|
18
|
-
|
19
|
-
attribute :_ary, GOBL::Types::Array.of(GOBL::Currency::ExchangeRate)
|
20
|
-
|
21
|
-
# @!method [](*args)
|
22
|
-
# Returns elements from the array
|
23
|
-
# @overload [](index)
|
24
|
-
# Returns the element in a specific position
|
25
|
-
# @param index [Integer] the position of the object
|
26
|
-
# @return [GOBL::Currency::ExchangeRate] the element in the `index` position
|
27
|
-
# @overload [](start, length)
|
28
|
-
# Returns all the elements within a range of positions
|
29
|
-
# @param start [Integer] start position of the range
|
30
|
-
# @param length [Integer] length of the range
|
31
|
-
# @return [Array<GOBL::Currency::ExchangeRate>] the elements in the range
|
32
|
-
# @overload [](range)
|
33
|
-
# Returns all the elements within a range
|
34
|
-
# @param range [Range] start and end positions of the range
|
35
|
-
# @return [Array<GOBL::Currency::ExchangeRate>] the elements in the range
|
36
|
-
#
|
37
|
-
# @!method each
|
38
|
-
# Iterates over the array elements
|
39
|
-
# @overload each(&block)
|
40
|
-
# Calls the given block with each element in the array
|
41
|
-
# @yield [element] element of the array
|
42
|
-
# @return [self] the object itself
|
43
|
-
# @overload each
|
44
|
-
# Returns an Enumerator that iterates over the array elements
|
45
|
-
# @return [Enumerator] the enumerator of the array elements
|
46
|
-
#
|
47
|
-
# @!method empty?
|
48
|
-
# Returns `true` if the number of elements in the array is zero, `false` otherwise.
|
49
|
-
# @return [Boolean] whether the array is empty or not
|
50
|
-
#
|
51
|
-
# @!method length
|
52
|
-
# Returns the number of elements in the array
|
53
|
-
# @return [Integer] the number of elements in the array
|
54
|
-
def_delegators :_ary, :[], :each, :empty?, :length
|
55
|
-
|
56
|
-
# Creates a new object from an array of GOBL data
|
57
|
-
#
|
58
|
-
# @param data [Array] an array of GOBL data
|
59
|
-
#
|
60
|
-
# @return [ExchangeRates] the object created from the given data
|
61
|
-
def self.from_gobl!(data)
|
62
|
-
new(_ary: data&.map { |item| GOBL::Currency::ExchangeRate.from_gobl!(item) })
|
63
|
-
end
|
64
|
-
|
65
|
-
# Returns an array of GOBL data representing the current object
|
66
|
-
#
|
67
|
-
# @return [Array<Hash>] the array of GOBL data that represents the current object
|
68
|
-
def to_gobl
|
69
|
-
_ary.map(&:to_gobl)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Returns a {ExchangeRates} object from a given array of structs. The array may
|
73
|
-
# contain {GOBL::Currency::ExchangeRate} objects or hashes. If hashes are provided, the constructor
|
74
|
-
# will call `GOBL::Currency::ExchangeRate#new` to generate the objects that will be part of the
|
75
|
-
# returned {ExchangeRates} object
|
76
|
-
#
|
77
|
-
# @param object [Array<GOBL::Currency::ExchangeRate, Hash>] the array containing the structs
|
78
|
-
#
|
79
|
-
# @return [ExchangeRates] the object corresponding to the given input
|
80
|
-
def self.new(object)
|
81
|
-
case object
|
82
|
-
when Array
|
83
|
-
super _ary: object
|
84
|
-
else # internal use, not to be used in public calls
|
85
|
-
super
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
12
|
+
ExchangeRates = [GOBL::Currency::ExchangeRate] # rubocop:disable Naming/ConstantName, Style/MutableConstant
|
89
13
|
end
|
90
14
|
end
|