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.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/data/tax/ES.json +841 -0
  3. data/data/tax/FR.json +47 -0
  4. data/data/tax/GB.json +56 -0
  5. data/data/tax/NL.json +60 -0
  6. data/home/cavalle/workspace/invopop/gobl.ruby/gobl.gemspec +30 -0
  7. data/lib/extensions.rb +12 -0
  8. data/lib/gobl/bill/advances.rb +90 -0
  9. data/lib/gobl/bill/charge.rb +121 -0
  10. data/lib/gobl/bill/delivery.rb +79 -0
  11. data/lib/gobl/bill/discount.rb +121 -0
  12. data/lib/gobl/bill/exchange_rates.rb +90 -0
  13. data/lib/gobl/bill/invoice.rb +209 -0
  14. data/lib/gobl/bill/invoice_type.rb +163 -0
  15. data/lib/gobl/bill/line.rb +121 -0
  16. data/lib/gobl/bill/line_charge.rb +79 -0
  17. data/lib/gobl/bill/line_discount.rb +79 -0
  18. data/lib/gobl/bill/ordering.rb +58 -0
  19. data/lib/gobl/bill/outlay.rb +107 -0
  20. data/lib/gobl/bill/payment.rb +79 -0
  21. data/lib/gobl/bill/preceding.rb +114 -0
  22. data/lib/gobl/bill/scheme_keys.rb +90 -0
  23. data/lib/gobl/bill/tax.rb +72 -0
  24. data/lib/gobl/bill/totals.rb +135 -0
  25. data/lib/gobl/cal/date.rb +106 -0
  26. data/lib/gobl/cal/period.rb +63 -0
  27. data/lib/gobl/config.rb +14 -0
  28. data/lib/gobl/currency/code.rb +322 -0
  29. data/lib/gobl/currency/exchange_rate.rb +65 -0
  30. data/lib/gobl/document.rb +70 -0
  31. data/lib/gobl/dsig/digest.rb +65 -0
  32. data/lib/gobl/dsig/signature.rb +106 -0
  33. data/lib/gobl/envelope.rb +77 -0
  34. data/lib/gobl/header.rb +98 -0
  35. data/lib/gobl/i18n/string.rb +72 -0
  36. data/lib/gobl/id.rb +80 -0
  37. data/lib/gobl/l10n/code.rb +106 -0
  38. data/lib/gobl/l10n/country_code.rb +405 -0
  39. data/lib/gobl/note/message.rb +72 -0
  40. data/lib/gobl/num/amount.rb +248 -0
  41. data/lib/gobl/num/percentage.rb +84 -0
  42. data/lib/gobl/operations/service_error.rb +10 -0
  43. data/lib/gobl/operations/validation_result.rb +46 -0
  44. data/lib/gobl/operations.rb +170 -0
  45. data/lib/gobl/org/address.rb +156 -0
  46. data/lib/gobl/org/code.rb +106 -0
  47. data/lib/gobl/org/coordinates.rb +79 -0
  48. data/lib/gobl/org/email.rb +79 -0
  49. data/lib/gobl/org/inbox.rb +86 -0
  50. data/lib/gobl/org/item.rb +121 -0
  51. data/lib/gobl/org/item_code.rb +65 -0
  52. data/lib/gobl/org/key.rb +106 -0
  53. data/lib/gobl/org/meta.rb +72 -0
  54. data/lib/gobl/org/name.rb +114 -0
  55. data/lib/gobl/org/note.rb +79 -0
  56. data/lib/gobl/org/note_key.rb +181 -0
  57. data/lib/gobl/org/party.rb +135 -0
  58. data/lib/gobl/org/person.rb +100 -0
  59. data/lib/gobl/org/registration.rb +99 -0
  60. data/lib/gobl/org/source_key.rb +161 -0
  61. data/lib/gobl/org/tax_identity.rb +93 -0
  62. data/lib/gobl/org/telephone.rb +72 -0
  63. data/lib/gobl/org/unit.rb +204 -0
  64. data/lib/gobl/pay/advance.rb +107 -0
  65. data/lib/gobl/pay/card.rb +65 -0
  66. data/lib/gobl/pay/credit_transfer.rb +86 -0
  67. data/lib/gobl/pay/direct_debit.rb +72 -0
  68. data/lib/gobl/pay/due_date.rb +86 -0
  69. data/lib/gobl/pay/instructions.rb +114 -0
  70. data/lib/gobl/pay/method_key.rb +163 -0
  71. data/lib/gobl/pay/online.rb +65 -0
  72. data/lib/gobl/pay/term_key.rb +166 -0
  73. data/lib/gobl/pay/terms.rb +79 -0
  74. data/lib/gobl/stamp.rb +63 -0
  75. data/lib/gobl/struct.rb +48 -0
  76. data/lib/gobl/tax/category.rb +83 -0
  77. data/lib/gobl/tax/category_total.rb +87 -0
  78. data/lib/gobl/tax/combo.rb +79 -0
  79. data/lib/gobl/tax/localities.rb +90 -0
  80. data/lib/gobl/tax/locality.rb +72 -0
  81. data/lib/gobl/tax/rate.rb +77 -0
  82. data/lib/gobl/tax/rate_total.rb +82 -0
  83. data/lib/gobl/tax/rate_total_surcharge.rb +63 -0
  84. data/lib/gobl/tax/rate_value.rb +79 -0
  85. data/lib/gobl/tax/region.rb +100 -0
  86. data/lib/gobl/tax/scheme.rb +86 -0
  87. data/lib/gobl/tax/schemes.rb +90 -0
  88. data/lib/gobl/tax/set.rb +90 -0
  89. data/lib/gobl/tax/total.rb +65 -0
  90. data/lib/gobl/types.rb +17 -0
  91. data/lib/gobl/uuid/uuid.rb +106 -0
  92. data/lib/gobl/version.rb +5 -0
  93. data/lib/gobl.rb +41 -0
  94. data/lib/gobl_extensions/document_helper.rb +45 -0
  95. data/lib/gobl_extensions/envelope_helper.rb +15 -0
  96. data/lib/gobl_extensions/i18n/value_keys_helper.rb +27 -0
  97. data/lib/gobl_extensions/tax/region_helper.rb +41 -0
  98. metadata +225 -0
@@ -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 Bill
11
+ # LineDiscount represents an amount deducted from the line, and will be applied before taxes.
12
+ class LineDiscount < GOBL::Struct
13
+ # The Schema ID of the GOBL LineDiscount structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/LineDiscount'
15
+
16
+ # @!attribute [r] percent
17
+ # Percentage if fixed amount not applied
18
+ # @return [GOBL::Num::Percentage]
19
+ attribute? :percent, GOBL::Types.Constructor(GOBL::Num::Percentage).optional
20
+
21
+ # @!attribute [r] amount
22
+ # Fixed discount amount to apply (calculated if percent present).
23
+ # @return [GOBL::Num::Amount]
24
+ attribute? :amount, GOBL::Types.Constructor(GOBL::Num::Amount).optional
25
+
26
+ # @!attribute [r] code
27
+ # Reason code.
28
+ # @return [String]
29
+ attribute? :code, GOBL::Types::String.optional
30
+
31
+ # @!attribute [r] reason
32
+ # Text description as to why the discount was applied
33
+ # @return [String]
34
+ attribute? :reason, 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 [LineDiscount] the object created from the given data
41
+ def self.from_gobl!(data)
42
+ data = GOBL::Types::Hash[data]
43
+
44
+ new(
45
+ percent: data['percent'] || nil,
46
+ amount: data['amount'] || nil,
47
+ code: data['code'],
48
+ reason: data['reason']
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
+ 'percent' => attributes[:percent]&.to_gobl,
58
+ 'amount' => attributes[:amount]&.to_gobl,
59
+ 'code' => attributes[:code],
60
+ 'reason' => attributes[:reason]
61
+ }.compact
62
+ end
63
+
64
+ # @!method self.new(attrs)
65
+ #
66
+ # Returns a {LineDiscount} 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 [LineDiscount] the object corresponding to the given input
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,58 @@
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 Bill
11
+ # Ordering allows additional order details to be appended
12
+ class Ordering < GOBL::Struct
13
+ # The Schema ID of the GOBL Ordering structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Ordering'
15
+
16
+ # @!attribute [r] seller
17
+ # Party who is selling the goods and is not responsible for taxes
18
+ # @return [GOBL::Org::Party]
19
+ attribute? :seller, GOBL::Org::Party.optional
20
+
21
+ # Creates a new object from a hash of GOBL data
22
+ #
23
+ # @param data [Hash] a hash of GOBL data
24
+ #
25
+ # @return [Ordering] the object created from the given data
26
+ def self.from_gobl!(data)
27
+ data = GOBL::Types::Hash[data]
28
+
29
+ new(
30
+ seller: data['seller'] ? GOBL::Org::Party.from_gobl!(data['seller']) : nil
31
+ )
32
+ end
33
+
34
+ # Returns a hash of GOBL data representing the current object
35
+ #
36
+ # @return [Hash] the array of GOBL data that represents the current object
37
+ def to_gobl
38
+ {
39
+ 'seller' => attributes[:seller]&.to_gobl
40
+ }.compact
41
+ end
42
+
43
+ # @!method self.new(attrs)
44
+ #
45
+ # Returns a {Ordering} object from a given hash of attributes. Nested
46
+ # attributes are supported: the constructor will instantiate the proper GOBL
47
+ # objects when nested hashes or arrays are given as part of the `attrs`
48
+ # parameter.
49
+ #
50
+ # The `new` method will only allow to create a new object if all attributes
51
+ # marked as mandatory and not calculated in the JSON schema are provided.
52
+ #
53
+ # @param attrs [Hash] the hash of attributes
54
+ #
55
+ # @return [Ordering] the object corresponding to the given input
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,107 @@
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 Bill
11
+ # Outlay represents a reimbursable expense that was paid for by the supplier and invoiced separately by the third party directly to the customer.
12
+ class Outlay < GOBL::Struct
13
+ # The Schema ID of the GOBL Outlay structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Outlay'
15
+
16
+ # @!attribute [r] uuid
17
+ # Unique identity for this outlay.
18
+ # @return [GOBL::UUID::UUID]
19
+ attribute? :uuid, GOBL::UUID::UUID.optional
20
+
21
+ # @!attribute [r] i
22
+ # Outlay number index inside the invoice for ordering (calculated).
23
+ # @return [Integer]
24
+ attribute? :i, GOBL::Types::Int.optional
25
+
26
+ # @!attribute [r] date
27
+ # When was the outlay made.
28
+ # @return [GOBL::Cal::Date]
29
+ attribute? :date, GOBL::Cal::Date.optional
30
+
31
+ # @!attribute [r] code
32
+ # Invoice number or other reference detail used to identify the outlay.
33
+ # @return [String]
34
+ attribute? :code, GOBL::Types::String.optional
35
+
36
+ # @!attribute [r] series
37
+ # Series of the outlay invoice.
38
+ # @return [String]
39
+ attribute? :series, GOBL::Types::String.optional
40
+
41
+ # @!attribute [r] desc
42
+ # Details on what the outlay was.
43
+ # @return [String]
44
+ attribute :desc, GOBL::Types::String
45
+
46
+ # @!attribute [r] supplier
47
+ # Who was the supplier of the outlay
48
+ # @return [GOBL::Org::Party]
49
+ attribute? :supplier, GOBL::Org::Party.optional
50
+
51
+ # @!attribute [r] amount
52
+ # Amount paid by the supplier.
53
+ # @return [GOBL::Num::Amount]
54
+ attribute :amount, GOBL::Types.Constructor(GOBL::Num::Amount)
55
+
56
+ # Creates a new object from a hash of GOBL data
57
+ #
58
+ # @param data [Hash] a hash of GOBL data
59
+ #
60
+ # @return [Outlay] the object created from the given data
61
+ def self.from_gobl!(data)
62
+ data = GOBL::Types::Hash[data]
63
+
64
+ new(
65
+ uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
66
+ i: data['i'],
67
+ date: data['date'] ? GOBL::Cal::Date.from_gobl!(data['date']) : nil,
68
+ code: data['code'],
69
+ series: data['series'],
70
+ desc: data['desc'],
71
+ supplier: data['supplier'] ? GOBL::Org::Party.from_gobl!(data['supplier']) : nil,
72
+ amount: data['amount']
73
+ )
74
+ end
75
+
76
+ # Returns a hash of GOBL data representing the current object
77
+ #
78
+ # @return [Hash] the array of GOBL data that represents the current object
79
+ def to_gobl
80
+ {
81
+ 'uuid' => attributes[:uuid]&.to_gobl,
82
+ 'i' => attributes[:i],
83
+ 'date' => attributes[:date]&.to_gobl,
84
+ 'code' => attributes[:code],
85
+ 'series' => attributes[:series],
86
+ 'desc' => attributes[:desc],
87
+ 'supplier' => attributes[:supplier]&.to_gobl,
88
+ 'amount' => attributes[:amount]&.to_gobl
89
+ }.compact
90
+ end
91
+
92
+ # @!method self.new(attrs)
93
+ #
94
+ # Returns a {Outlay} object from a given hash of attributes. Nested
95
+ # attributes are supported: the constructor will instantiate the proper GOBL
96
+ # objects when nested hashes or arrays are given as part of the `attrs`
97
+ # parameter.
98
+ #
99
+ # The `new` method will only allow to create a new object if all attributes
100
+ # marked as mandatory and not calculated in the JSON schema are provided.
101
+ #
102
+ # @param attrs [Hash] the hash of attributes
103
+ #
104
+ # @return [Outlay] the object corresponding to the given input
105
+ end
106
+ end
107
+ 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 Bill
11
+ # Payment contains details as to how the invoice should be paid.
12
+ class Payment < GOBL::Struct
13
+ # The Schema ID of the GOBL Payment structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Payment'
15
+
16
+ # @!attribute [r] payer
17
+ # The party responsible for paying for the invoice, if not the customer.
18
+ # @return [GOBL::Org::Party]
19
+ attribute? :payer, GOBL::Org::Party.optional
20
+
21
+ # @!attribute [r] terms
22
+ # Payment terms or conditions.
23
+ # @return [GOBL::Pay::Terms]
24
+ attribute? :terms, GOBL::Pay::Terms.optional
25
+
26
+ # @!attribute [r] advances
27
+ # Any amounts that have been paid in advance and should be deducted from the amount due.
28
+ # @return [Advances]
29
+ attribute? :advances, Advances.optional
30
+
31
+ # @!attribute [r] instructions
32
+ # Details on how payment should be made.
33
+ # @return [GOBL::Pay::Instructions]
34
+ attribute? :instructions, GOBL::Pay::Instructions.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 [Payment] the object created from the given data
41
+ def self.from_gobl!(data)
42
+ data = GOBL::Types::Hash[data]
43
+
44
+ new(
45
+ payer: data['payer'] ? GOBL::Org::Party.from_gobl!(data['payer']) : nil,
46
+ terms: data['terms'] ? GOBL::Pay::Terms.from_gobl!(data['terms']) : nil,
47
+ advances: data['advances'] ? Advances.from_gobl!(data['advances']) : nil,
48
+ instructions: data['instructions'] ? GOBL::Pay::Instructions.from_gobl!(data['instructions']) : 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
+ 'payer' => attributes[:payer]&.to_gobl,
58
+ 'terms' => attributes[:terms]&.to_gobl,
59
+ 'advances' => attributes[:advances]&.to_gobl,
60
+ 'instructions' => attributes[:instructions]&.to_gobl
61
+ }.compact
62
+ end
63
+
64
+ # @!method self.new(attrs)
65
+ #
66
+ # Returns a {Payment} 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 [Payment] the object corresponding to the given input
77
+ end
78
+ end
79
+ end
@@ -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 Bill
11
+ # Preceding allows for information to be provided about a previous invoice that this one will replace or subtract from.
12
+ class Preceding < GOBL::Struct
13
+ # The Schema ID of the GOBL Preceding structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Preceding'
15
+
16
+ # @!attribute [r] uuid
17
+ # Preceding document's UUID if available can be useful for tracing.
18
+ # @return [GOBL::UUID::UUID]
19
+ attribute? :uuid, GOBL::UUID::UUID.optional
20
+
21
+ # @!attribute [r] code
22
+ # Identity code of the previous invoice.
23
+ # @return [String]
24
+ attribute :code, GOBL::Types::String
25
+
26
+ # @!attribute [r] series
27
+ # Additional identification details
28
+ # @return [String]
29
+ attribute? :series, GOBL::Types::String.optional
30
+
31
+ # @!attribute [r] issue_date
32
+ # When the preceding invoice was issued.
33
+ # @return [GOBL::Cal::Date]
34
+ attribute :issue_date, GOBL::Cal::Date
35
+
36
+ # @!attribute [r] period
37
+ # Tax period in which the previous invoice has an effect.
38
+ # @return [GOBL::Cal::Period]
39
+ attribute? :period, GOBL::Cal::Period.optional
40
+
41
+ # @!attribute [r] corrections
42
+ # Specific codes for the corrections made.
43
+ # @return [Array<String>]
44
+ attribute? :corrections, GOBL::Types::Array.of(GOBL::Types::String).optional
45
+
46
+ # @!attribute [r] correction_method
47
+ # How has the previous invoice been corrected?
48
+ # @return [String]
49
+ attribute? :correction_method, GOBL::Types::String.optional
50
+
51
+ # @!attribute [r] notes
52
+ # Additional details regarding preceding invoice
53
+ # @return [String]
54
+ attribute? :notes, GOBL::Types::String.optional
55
+
56
+ # @!attribute [r] meta
57
+ # Additional semi-structured data that may be useful in specific regions
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 [Preceding] the object created from the given data
66
+ def self.from_gobl!(data)
67
+ data = GOBL::Types::Hash[data]
68
+
69
+ new(
70
+ uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
71
+ code: data['code'],
72
+ series: data['series'],
73
+ issue_date: GOBL::Cal::Date.from_gobl!(data['issue_date']),
74
+ period: data['period'] ? GOBL::Cal::Period.from_gobl!(data['period']) : nil,
75
+ corrections: data['corrections']&.map { |item| item },
76
+ correction_method: data['correction_method'],
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
+ 'uuid' => attributes[:uuid]&.to_gobl,
88
+ 'code' => attributes[:code],
89
+ 'series' => attributes[:series],
90
+ 'issue_date' => attributes[:issue_date]&.to_gobl,
91
+ 'period' => attributes[:period]&.to_gobl,
92
+ 'corrections' => attributes[:corrections]&.map { |item| item },
93
+ 'correction_method' => attributes[:correction_method],
94
+ 'notes' => attributes[:notes],
95
+ 'meta' => attributes[:meta]&.to_gobl
96
+ }.compact
97
+ end
98
+
99
+ # @!method self.new(attrs)
100
+ #
101
+ # Returns a {Preceding} 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 [Preceding] the object corresponding to the given input
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,90 @@
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 Bill
11
+ # SchemeKeys stores a list of keys that makes it easier to perform matches.
12
+ class SchemeKeys < GOBL::Struct
13
+ extend Forwardable
14
+ include Enumerable
15
+
16
+ # The Schema ID of the GOBL SchemeKeys structure
17
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/SchemeKeys'
18
+
19
+ attribute :_ary, GOBL::Types::Array.of(GOBL::Org::Key)
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::Org::Key] 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::Org::Key>] 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::Org::Key>] 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 [SchemeKeys] the object created from the given data
61
+ def self.from_gobl!(data)
62
+ new(_ary: data&.map { |item| GOBL::Org::Key.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 {SchemeKeys} object from a given array of structs. The array may
73
+ # contain {GOBL::Org::Key} objects or hashes. If hashes are provided, the constructor
74
+ # will call `GOBL::Org::Key#new` to generate the objects that will be part of the
75
+ # returned {SchemeKeys} object
76
+ #
77
+ # @param object [Array<GOBL::Org::Key, Hash>] the array containing the structs
78
+ #
79
+ # @return [SchemeKeys] 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
89
+ end
90
+ end
@@ -0,0 +1,72 @@
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 Bill
11
+ # Tax defines a summary of the taxes which may be applied to an invoice.
12
+ class Tax < GOBL::Struct
13
+ # The Schema ID of the GOBL Tax structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Tax'
15
+
16
+ # @!attribute [r] prices_include
17
+ # Category of the tax already included in the line item prices, especially useful for B2C retailers with customers who prefer final prices inclusive of tax.
18
+ # @return [GOBL::Org::Code]
19
+ attribute? :prices_include, GOBL::Org::Code.optional
20
+
21
+ # @!attribute [r] schemes
22
+ # Special tax schemes that apply to this invoice according to local requirements.
23
+ # @return [SchemeKeys]
24
+ attribute? :schemes, SchemeKeys.optional
25
+
26
+ # @!attribute [r] meta
27
+ # Any additional data that may be required for processing, but should never be relied upon by recipients.
28
+ # @return [GOBL::Org::Meta]
29
+ attribute? :meta, GOBL::Org::Meta.optional
30
+
31
+ # Creates a new object from a hash of GOBL data
32
+ #
33
+ # @param data [Hash] a hash of GOBL data
34
+ #
35
+ # @return [Tax] the object created from the given data
36
+ def self.from_gobl!(data)
37
+ data = GOBL::Types::Hash[data]
38
+
39
+ new(
40
+ prices_include: data['prices_include'] ? GOBL::Org::Code.from_gobl!(data['prices_include']) : nil,
41
+ schemes: data['schemes'] ? SchemeKeys.from_gobl!(data['schemes']) : nil,
42
+ meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
43
+ )
44
+ end
45
+
46
+ # Returns a hash of GOBL data representing the current object
47
+ #
48
+ # @return [Hash] the array of GOBL data that represents the current object
49
+ def to_gobl
50
+ {
51
+ 'prices_include' => attributes[:prices_include]&.to_gobl,
52
+ 'schemes' => attributes[:schemes]&.to_gobl,
53
+ 'meta' => attributes[:meta]&.to_gobl
54
+ }.compact
55
+ end
56
+
57
+ # @!method self.new(attrs)
58
+ #
59
+ # Returns a {Tax} object from a given hash of attributes. Nested
60
+ # attributes are supported: the constructor will instantiate the proper GOBL
61
+ # objects when nested hashes or arrays are given as part of the `attrs`
62
+ # parameter.
63
+ #
64
+ # The `new` method will only allow to create a new object if all attributes
65
+ # marked as mandatory and not calculated in the JSON schema are provided.
66
+ #
67
+ # @param attrs [Hash] the hash of attributes
68
+ #
69
+ # @return [Tax] the object corresponding to the given input
70
+ end
71
+ end
72
+ end