gobl 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
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,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GOBLExtensions
4
+ # Additional methods for the generated {GOBL::Document} class
5
+ module DocumentHelper
6
+ # Returns the Schema ID of the current document
7
+ #
8
+ # @return [GOBL::ID] the Schema ID
9
+ def schema
10
+ @schema ||= GOBL::ID.new(_value['$schema'])
11
+ end
12
+
13
+ # Extracts the GOBL struct embedded in the document. It determines the type of document
14
+ # currently embedded by reading the schema and attemps to instantiate the detected
15
+ # class.
16
+ #
17
+ # @return [GOBL::Struct] the GOBL struct embedded in the document
18
+ def extract
19
+ raise 'unknown schema' unless schema.gobl?
20
+
21
+ typs = ['GOBL']
22
+ schema.modules.each do |mod|
23
+ typs << mod.underscore.camelize
24
+ end
25
+ typs << schema.name.underscore.camelize
26
+ klass = typs.join('::').constantize
27
+
28
+ # Sanity check
29
+ raise "#{klass.name}::SCHEMA_ID expected to be '#{schema}'" unless schema == klass::SCHEMA_ID
30
+
31
+ klass.from_gobl!(_value.except('$schema'))
32
+ end
33
+
34
+ module ClassMethods
35
+ # Embeds the given GOBL struct in a new document injecting the proper Schema ID.
36
+ #
37
+ # @return [Document] the document embedding the given struct
38
+ def embed(struct)
39
+ from_gobl! struct.to_gobl.merge(
40
+ '$schema' => struct.class::SCHEMA_ID
41
+ )
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GOBLExtensions
4
+ # Additional methods for the generated {GOBL::Envelope} class
5
+ module EnvelopeHelper
6
+ # Extracts the GOBL struct embedded in the envelope's document
7
+ #
8
+ # @see GOBLExtensions::DocumentHelper#extract
9
+ #
10
+ # @return [GOBL::Struct] the GOBL struct embedded in the envelope's document
11
+ def extract
12
+ doc.extract
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GOBLExtensions
4
+ module I18n
5
+ # Additional methods for the generated {GOBL::I18n::String} class
6
+ module ValueKeysHelper
7
+ # Enables dynamic getter methods for the mapped keys.
8
+ #
9
+ # @example
10
+ # str = GOBL::I18n::String.new(en: 'Name', es: 'Nombre')
11
+ # str.en #=> "Name"
12
+ # str.es #=> "Nombre"
13
+ def method_missing(method_name, *args, &block)
14
+ if _value.key?(method_name) || _value.key?(method_name.to_s)
15
+ _value[method_name] || _value[method_name.to_s]
16
+ else
17
+ super
18
+ end
19
+ end
20
+
21
+ # @api private
22
+ def respond_to_missing?(method_name, *)
23
+ _value.key?(method_name) || _value.key?(method_name.to_s) || super
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/files'
4
+
5
+ module GOBLExtensions
6
+ module Tax
7
+ # Additional methods for the generated {GOBL::Tax::Region} class
8
+ module RegionHelper
9
+ module ClassMethods
10
+ # Loads a {GOBL::Tax::Region} object identified by the given code with all its data
11
+ #
12
+ # @param code [String] the code of the region to load
13
+ #
14
+ # @return [Region] the requested region
15
+ def fetch(code)
16
+ regions[code] ||= load_region(code)
17
+ end
18
+
19
+ protected
20
+
21
+ def files
22
+ @files ||= Dry::Files.new
23
+ end
24
+
25
+ # map of region ID to region instance
26
+ def regions
27
+ @regions ||= {}
28
+ end
29
+
30
+ def load_region(code)
31
+ path = files.join("#{__dir__}/../../../data/tax", "#{code}.json")
32
+ msg = "region definition for #{code} does not exist at #{path}"
33
+ raise StandardError, msg unless files.exist?(path)
34
+
35
+ data = files.read(path)
36
+ from_json!(data)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,225 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gobl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - David Lilue
8
+ - Sam Lown
9
+ - Juanjo Molinero
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2022-10-05 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '6.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '6.1'
29
+ - !ruby/object:Gem::Dependency
30
+ name: dry-files
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: 0.1.0
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: 0.1.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: dry-struct
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 1.4.0
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: 1.4.0
57
+ - !ruby/object:Gem::Dependency
58
+ name: dry-types
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: 1.5.1
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: 1.5.1
71
+ - !ruby/object:Gem::Dependency
72
+ name: json
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: 2.6.1
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: 2.6.1
85
+ - !ruby/object:Gem::Dependency
86
+ name: zeitwerk
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: 2.5.1
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: 2.5.1
99
+ description:
100
+ email:
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - "/home/cavalle/workspace/invopop/gobl.ruby/gobl.gemspec"
106
+ - data/tax/ES.json
107
+ - data/tax/FR.json
108
+ - data/tax/GB.json
109
+ - data/tax/NL.json
110
+ - lib/extensions.rb
111
+ - lib/gobl.rb
112
+ - lib/gobl/bill/advances.rb
113
+ - lib/gobl/bill/charge.rb
114
+ - lib/gobl/bill/delivery.rb
115
+ - lib/gobl/bill/discount.rb
116
+ - lib/gobl/bill/exchange_rates.rb
117
+ - lib/gobl/bill/invoice.rb
118
+ - lib/gobl/bill/invoice_type.rb
119
+ - lib/gobl/bill/line.rb
120
+ - lib/gobl/bill/line_charge.rb
121
+ - lib/gobl/bill/line_discount.rb
122
+ - lib/gobl/bill/ordering.rb
123
+ - lib/gobl/bill/outlay.rb
124
+ - lib/gobl/bill/payment.rb
125
+ - lib/gobl/bill/preceding.rb
126
+ - lib/gobl/bill/scheme_keys.rb
127
+ - lib/gobl/bill/tax.rb
128
+ - lib/gobl/bill/totals.rb
129
+ - lib/gobl/cal/date.rb
130
+ - lib/gobl/cal/period.rb
131
+ - lib/gobl/config.rb
132
+ - lib/gobl/currency/code.rb
133
+ - lib/gobl/currency/exchange_rate.rb
134
+ - lib/gobl/document.rb
135
+ - lib/gobl/dsig/digest.rb
136
+ - lib/gobl/dsig/signature.rb
137
+ - lib/gobl/envelope.rb
138
+ - lib/gobl/header.rb
139
+ - lib/gobl/i18n/string.rb
140
+ - lib/gobl/id.rb
141
+ - lib/gobl/l10n/code.rb
142
+ - lib/gobl/l10n/country_code.rb
143
+ - lib/gobl/note/message.rb
144
+ - lib/gobl/num/amount.rb
145
+ - lib/gobl/num/percentage.rb
146
+ - lib/gobl/operations.rb
147
+ - lib/gobl/operations/service_error.rb
148
+ - lib/gobl/operations/validation_result.rb
149
+ - lib/gobl/org/address.rb
150
+ - lib/gobl/org/code.rb
151
+ - lib/gobl/org/coordinates.rb
152
+ - lib/gobl/org/email.rb
153
+ - lib/gobl/org/inbox.rb
154
+ - lib/gobl/org/item.rb
155
+ - lib/gobl/org/item_code.rb
156
+ - lib/gobl/org/key.rb
157
+ - lib/gobl/org/meta.rb
158
+ - lib/gobl/org/name.rb
159
+ - lib/gobl/org/note.rb
160
+ - lib/gobl/org/note_key.rb
161
+ - lib/gobl/org/party.rb
162
+ - lib/gobl/org/person.rb
163
+ - lib/gobl/org/registration.rb
164
+ - lib/gobl/org/source_key.rb
165
+ - lib/gobl/org/tax_identity.rb
166
+ - lib/gobl/org/telephone.rb
167
+ - lib/gobl/org/unit.rb
168
+ - lib/gobl/pay/advance.rb
169
+ - lib/gobl/pay/card.rb
170
+ - lib/gobl/pay/credit_transfer.rb
171
+ - lib/gobl/pay/direct_debit.rb
172
+ - lib/gobl/pay/due_date.rb
173
+ - lib/gobl/pay/instructions.rb
174
+ - lib/gobl/pay/method_key.rb
175
+ - lib/gobl/pay/online.rb
176
+ - lib/gobl/pay/term_key.rb
177
+ - lib/gobl/pay/terms.rb
178
+ - lib/gobl/stamp.rb
179
+ - lib/gobl/struct.rb
180
+ - lib/gobl/tax/category.rb
181
+ - lib/gobl/tax/category_total.rb
182
+ - lib/gobl/tax/combo.rb
183
+ - lib/gobl/tax/localities.rb
184
+ - lib/gobl/tax/locality.rb
185
+ - lib/gobl/tax/rate.rb
186
+ - lib/gobl/tax/rate_total.rb
187
+ - lib/gobl/tax/rate_total_surcharge.rb
188
+ - lib/gobl/tax/rate_value.rb
189
+ - lib/gobl/tax/region.rb
190
+ - lib/gobl/tax/scheme.rb
191
+ - lib/gobl/tax/schemes.rb
192
+ - lib/gobl/tax/set.rb
193
+ - lib/gobl/tax/total.rb
194
+ - lib/gobl/types.rb
195
+ - lib/gobl/uuid/uuid.rb
196
+ - lib/gobl/version.rb
197
+ - lib/gobl_extensions/document_helper.rb
198
+ - lib/gobl_extensions/envelope_helper.rb
199
+ - lib/gobl_extensions/i18n/value_keys_helper.rb
200
+ - lib/gobl_extensions/tax/region_helper.rb
201
+ homepage: https://github.com/invopop/gobl.ruby
202
+ licenses:
203
+ - Apache-2.0
204
+ metadata:
205
+ rubygems_mfa_required: 'true'
206
+ post_install_message:
207
+ rdoc_options: []
208
+ require_paths:
209
+ - lib
210
+ required_ruby_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '2.7'
215
+ required_rubygems_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: 3.1.4
220
+ requirements: []
221
+ rubygems_version: 3.3.7
222
+ signing_key:
223
+ specification_version: 4
224
+ summary: Minimalist ruby version of the GOBL library
225
+ test_files: []