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,106 @@
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 L10n
11
+ # Code is used for short identifies like country or state codes.
12
+ class Code < GOBL::Struct
13
+ # The Schema ID of the GOBL Code structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/l10n/code'
15
+
16
+ attribute :_value, GOBL::Types::String
17
+ private :_value
18
+
19
+ # Creates a new object from a GOBL value
20
+ #
21
+ # @param data [String] the GOBL value
22
+ #
23
+ # @return [Code] the object created from the given data
24
+ def self.from_gobl!(data)
25
+ new(_value: data)
26
+ end
27
+
28
+ # Returns a GOBL value representing the current object
29
+ #
30
+ # @return [String] the GOBL value that represents the current object
31
+ def to_gobl
32
+ _value
33
+ end
34
+
35
+ # Returns a {Code} that corresponds to a given object. The object can be a
36
+ # `Symbol`, a `String` or anything coercible into one (via `#to_s`).
37
+ #
38
+ # @param object [Symbol, String, #to_s] the value of the object.
39
+ #
40
+ # @return [Code] the object corresponding to the given value.
41
+ #
42
+ # @example Instantiating from a symbol
43
+ # code = GOBL::L10n::Code.new(:value)
44
+ #
45
+ # @example Instantiating from a string
46
+ # code = GOBL::L10n::Code.new('value')
47
+ def self.new(object)
48
+ case object
49
+ when Hash, self # internal use, not to be used in public calls
50
+ super
51
+ when Symbol
52
+ new object.to_s
53
+ else
54
+ super _value: object.to_s
55
+ end
56
+ end
57
+
58
+ # Returns the string representation of the current object
59
+ #
60
+ # @return [String] the string representation of the current object
61
+ def to_s
62
+ _value.to_s
63
+ end
64
+
65
+ # Returns the symbol representation of the current object
66
+ #
67
+ # @return [Symbol] the symbol representation of the current object
68
+ def to_sym
69
+ to_s.parameterize.underscore.to_sym
70
+ end
71
+
72
+ # Returns whether the current object is equivalent to a given one. In addition
73
+ # to {Code} objects, the current object can be compared to a `Symbol`, a
74
+ # `String` or anything coercible into one (via `#to_s`)
75
+ #
76
+ # @param other [Code, Symbol, String, #to_s] the other object to compare to
77
+ #
78
+ # @return [Boolean] `true` if the objects are equivalent, `false` otherwise
79
+ #
80
+ # @example Comparing to another {Code} object
81
+ # code = GOBL::L10n::Code.new('value')
82
+ # code == GOBL::L10n::Code.new('value') #=> true
83
+ # code == GOBL::L10n::Code.new('other') #=> false
84
+ #
85
+ # @example Comparing to a string
86
+ # code = GOBL::L10n::Code.new('value')
87
+ # code == 'value' #=> true
88
+ # code == 'other' #=> false
89
+ #
90
+ # @example Comparing to a symbol
91
+ # code = GOBL::L10n::Code.new('value')
92
+ # code == :value #=> true
93
+ # code == :other #=> false
94
+ def ==(other)
95
+ case other
96
+ when self.class
97
+ super
98
+ when Symbol
99
+ to_sym == other
100
+ else
101
+ to_s == other.to_s
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,405 @@
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 L10n
11
+ # Defines an ISO 3166-2 country code
12
+ class CountryCode < GOBL::Struct
13
+ # The Schema ID of the GOBL CountryCode structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/l10n/country-code'
15
+
16
+ # The enumeration of values of the object and their descriptions (Values different to these are not allowed)
17
+ ENUM = {
18
+ 'AF' => 'Afghanistan',
19
+ 'AX' => 'Åland Islands',
20
+ 'AL' => 'Albania',
21
+ 'DZ' => 'Algeria',
22
+ 'AS' => 'American Samoa',
23
+ 'AD' => 'Andorra',
24
+ 'AO' => 'Angola',
25
+ 'AI' => 'Anguilla',
26
+ 'AQ' => 'Antarctica',
27
+ 'AG' => 'Antigua and Barbuda',
28
+ 'AR' => 'Argentina',
29
+ 'AM' => 'Armenia',
30
+ 'AW' => 'Aruba',
31
+ 'AU' => 'Australia ',
32
+ 'AT' => 'Austria',
33
+ 'AZ' => 'Azerbaijan',
34
+ 'BS' => 'Bahamas (the)',
35
+ 'BH' => 'Bahrain',
36
+ 'BD' => 'Bangladesh',
37
+ 'BB' => 'Barbados',
38
+ 'BY' => 'Belarus',
39
+ 'BE' => 'Belgium',
40
+ 'BZ' => 'Belize',
41
+ 'BJ' => 'Benin',
42
+ 'BM' => 'Bermuda',
43
+ 'BT' => 'Bhutan',
44
+ 'BO' => 'Bolivia (Plurinational State of)',
45
+ 'BQ' => 'Bonaire, Sint Eustatius and Saba',
46
+ 'BA' => 'Bosnia and Herzegovina',
47
+ 'BW' => 'Botswana',
48
+ 'BV' => 'Bouvet Island',
49
+ 'BR' => 'Brazil',
50
+ 'IO' => 'British Indian Ocean Territory (the)',
51
+ 'BN' => 'Brunei Darussalam',
52
+ 'BG' => 'Bulgaria',
53
+ 'BF' => 'Burkina Faso',
54
+ 'BI' => 'Burundi',
55
+ 'CV' => 'Cabo Verde',
56
+ 'KH' => 'Cambodia',
57
+ 'CM' => 'Cameroon',
58
+ 'CA' => 'Canada',
59
+ 'KY' => 'Cayman Islands (the)',
60
+ 'CF' => 'Central African Republic (the)',
61
+ 'TD' => 'Chad',
62
+ 'CL' => 'Chile',
63
+ 'CN' => 'China',
64
+ 'CX' => 'Christmas Island',
65
+ 'CC' => 'Cocos (Keeling) Islands (the)',
66
+ 'CO' => 'Colombia',
67
+ 'KM' => 'Comoros (the)',
68
+ 'CG' => 'Congo (the Democratic Republic of the)',
69
+ 'CD' => 'Congo (the)',
70
+ 'CK' => 'Cook Islands (the)',
71
+ 'CR' => 'Costa Rica',
72
+ 'CI' => 'Côte dIvoireIvoire',
73
+ 'HR' => 'Croatia',
74
+ 'CU' => 'Cuba',
75
+ 'CW' => 'Curaçao',
76
+ 'CY' => 'Cyprus',
77
+ 'CZ' => 'Czechia',
78
+ 'DK' => 'Denmark',
79
+ 'DJ' => 'Djibouti',
80
+ 'DM' => 'Dominica',
81
+ 'DO' => 'Dominican Republic (the)',
82
+ 'EC' => 'Ecuador',
83
+ 'EG' => 'Egypt',
84
+ 'SV' => 'El Salvador',
85
+ 'GQ' => 'Equatorial Guinea',
86
+ 'ER' => 'Eritrea',
87
+ 'EE' => 'Estonia',
88
+ 'SZ' => 'Eswatini',
89
+ 'ET' => 'Ethiopia',
90
+ 'FK' => 'Falkland Islands (the)',
91
+ 'FO' => 'Faroe Islands (the)',
92
+ 'FJ' => 'Fiji',
93
+ 'FI' => 'Finland',
94
+ 'FR' => 'France',
95
+ 'GF' => 'French Guiana',
96
+ 'PF' => 'French Polynesia',
97
+ 'TF' => 'French Southern Territories (the) ',
98
+ 'GA' => 'Gabon',
99
+ 'GM' => 'Gambia (the)',
100
+ 'GE' => 'Georgia',
101
+ 'DE' => 'Germany',
102
+ 'GH' => 'Ghana',
103
+ 'GI' => 'Gibraltar',
104
+ 'GR' => 'Greece',
105
+ 'GL' => 'Greenland',
106
+ 'GD' => 'Grenada',
107
+ 'GP' => 'Guadeloupe',
108
+ 'GU' => 'Guam',
109
+ 'GT' => 'Guatemala',
110
+ 'GG' => 'Guernsey',
111
+ 'GN' => 'Guinea',
112
+ 'GW' => 'Guinea-Bissau',
113
+ 'GY' => 'Guyana',
114
+ 'HT' => 'Haiti',
115
+ 'HM' => 'Heard Island and McDonald Islands',
116
+ 'VA' => 'Holy See (the)',
117
+ 'HN' => 'Honduras',
118
+ 'HK' => 'Hong Kong',
119
+ 'HU' => 'Hungary',
120
+ 'IS' => 'Iceland',
121
+ 'IN' => 'India',
122
+ 'ID' => 'Indonesia',
123
+ 'IR' => 'Iran (Islamic Republic of)',
124
+ 'IQ' => 'Iraq',
125
+ 'IE' => 'Ireland',
126
+ 'IM' => 'Isle of Man',
127
+ 'IL' => 'Israel',
128
+ 'IT' => 'Italy',
129
+ 'JM' => 'Jamaica',
130
+ 'JP' => 'Japan',
131
+ 'JE' => 'Jersey',
132
+ 'JO' => 'Jordan',
133
+ 'KZ' => 'Kazakhstan',
134
+ 'KE' => 'Kenya',
135
+ 'KI' => 'Kiribati',
136
+ 'KP' => 'Korea (the Democratic Peoples Republic of)s Republic of)',
137
+ 'KR' => 'Korea (the Republic of)',
138
+ 'KW' => 'Kuwait',
139
+ 'KG' => 'Kyrgyzstan',
140
+ 'LA' => 'Lao Peoples Democratic Republic (the)s Democratic Republic (the)',
141
+ 'LV' => 'Latvia',
142
+ 'LB' => 'Lebanon',
143
+ 'LS' => 'Lesotho',
144
+ 'LR' => 'Liberia',
145
+ 'LY' => 'Libya',
146
+ 'LI' => 'Liechtenstein',
147
+ 'LT' => 'Lithuania',
148
+ 'LU' => 'Luxembourg',
149
+ 'MO' => 'Macao',
150
+ 'MK' => 'North Macedonia',
151
+ 'MG' => 'Madagascar',
152
+ 'MW' => 'Malawi',
153
+ 'MY' => 'Malaysia',
154
+ 'MV' => 'Maldives',
155
+ 'ML' => 'Mali',
156
+ 'MT' => 'Malta',
157
+ 'MH' => 'Marshall Islands (the)',
158
+ 'MQ' => 'Martinique',
159
+ 'MR' => 'Mauritania',
160
+ 'MU' => 'Mauritius',
161
+ 'YT' => 'Mayotte',
162
+ 'MX' => 'Mexico',
163
+ 'FM' => 'Micronesia (Federated States of)',
164
+ 'MD' => 'Moldova (the Republic of)',
165
+ 'MC' => 'Monaco',
166
+ 'MN' => 'Mongolia',
167
+ 'ME' => 'Montenegro',
168
+ 'MS' => 'Montserrat',
169
+ 'MA' => 'Morocco',
170
+ 'MZ' => 'Mozambique',
171
+ 'MM' => 'Myanmar',
172
+ 'NA' => 'Namibia',
173
+ 'NR' => 'Nauru',
174
+ 'NP' => 'Nepal',
175
+ 'NL' => 'Netherlands (the)',
176
+ 'NC' => 'New Caledonia',
177
+ 'NZ' => 'New Zealand',
178
+ 'NI' => 'Nicaragua',
179
+ 'NE' => 'Niger (the)',
180
+ 'NG' => 'Nigeria',
181
+ 'NU' => 'Niue',
182
+ 'NF' => 'Norfolk Island',
183
+ 'MP' => 'Northern Mariana Islands (the)',
184
+ 'NO' => 'Norway',
185
+ 'OM' => 'Oman',
186
+ 'PK' => 'Pakistan',
187
+ 'PW' => 'Palau',
188
+ 'PS' => 'Palestine, State of',
189
+ 'PA' => 'Panama',
190
+ 'PG' => 'Papua New Guinea',
191
+ 'PY' => 'Paraguay',
192
+ 'PE' => 'Peru',
193
+ 'PH' => 'Philippines (the)',
194
+ 'PN' => 'Pitcairn',
195
+ 'PL' => 'Poland',
196
+ 'PT' => 'Portugal',
197
+ 'PR' => 'Puerto Rico',
198
+ 'QA' => 'Qatar',
199
+ 'RE' => 'Réunion',
200
+ 'RO' => 'Romania',
201
+ 'RU' => 'Russian Federation (the)',
202
+ 'RW' => 'Rwanda',
203
+ 'BL' => 'Saint Barthélemy',
204
+ 'SH' => 'Saint Helena, Ascension and Tristan da Cunha',
205
+ 'KN' => 'Saint Kitts and Nevis',
206
+ 'LC' => 'Saint Lucia',
207
+ 'MF' => 'Saint Martin (French part)',
208
+ 'PM' => 'Saint Pierre and Miquelon',
209
+ 'VC' => 'Saint Vincent and the Grenadines',
210
+ 'WS' => 'Samoa',
211
+ 'SM' => 'San Marino',
212
+ 'ST' => 'Sao Tome and Principe',
213
+ 'SA' => 'Saudi Arabia',
214
+ 'SN' => 'Senegal',
215
+ 'RS' => 'Serbia',
216
+ 'SC' => 'Seychelles',
217
+ 'SL' => 'Sierra Leone',
218
+ 'SG' => 'Singapore',
219
+ 'SX' => 'Sint Maarten (Dutch part)',
220
+ 'SK' => 'Slovakia',
221
+ 'SI' => 'Slovenia',
222
+ 'SB' => 'Solomon Islands',
223
+ 'SO' => 'Somalia',
224
+ 'ZA' => 'South Africa',
225
+ 'GS' => 'South Georgia and the South Sandwich Islands',
226
+ 'SS' => 'South Sudan',
227
+ 'ES' => 'Spain',
228
+ 'LK' => 'Sri Lanka',
229
+ 'SD' => 'Sudan (the)',
230
+ 'SR' => 'Suriname',
231
+ 'SJ' => 'Svalbard and Jan Mayen',
232
+ 'SE' => 'Sweden',
233
+ 'CH' => 'Switzerland',
234
+ 'SY' => 'Syrian Arab Republic (the)',
235
+ 'TW' => 'Taiwan (Province of China)',
236
+ 'TJ' => 'Tajikistan',
237
+ 'TZ' => 'Tanzania, the United Republic of',
238
+ 'TH' => 'Thailand',
239
+ 'TL' => 'Timor-Leste ',
240
+ 'TG' => 'Togo',
241
+ 'TK' => 'Tokelau',
242
+ 'TO' => 'Tonga',
243
+ 'TT' => 'Trinidad and Tobago',
244
+ 'TN' => 'Tunisia',
245
+ 'TR' => 'Türkiye',
246
+ 'TM' => 'Turkmenistan',
247
+ 'TC' => 'Turks and Caicos Islands (the)',
248
+ 'TV' => 'Tuvalu',
249
+ 'UG' => 'Uganda',
250
+ 'UA' => 'Ukraine',
251
+ 'AE' => 'United Arab Emirates (the)',
252
+ 'GB' => 'United Kingdom of Great Britain and Northern Ireland (the)',
253
+ 'US' => 'United States of America (the)',
254
+ 'UM' => 'United States Minor Outlying Islands (the)',
255
+ 'UY' => 'Uruguay',
256
+ 'UZ' => 'Uzbekistan',
257
+ 'VU' => 'Vanuatu',
258
+ 'VE' => 'Venezuela (Bolivarian Republic of)',
259
+ 'VN' => 'Viet Nam',
260
+ 'VG' => 'Virgin Islands (British)',
261
+ 'VI' => 'Virgin Islands (U.S.)',
262
+ 'WF' => 'Wallis and Futuna',
263
+ 'EH' => 'Western Sahara',
264
+ 'YE' => 'Yemen',
265
+ 'ZM' => 'Zambia',
266
+ 'ZW' => 'Zimbabwe'
267
+ }.freeze
268
+
269
+ attribute :_value, GOBL::Types::String.enum(*ENUM.keys)
270
+ private :_value
271
+
272
+ # Creates a new object from a GOBL value
273
+ #
274
+ # @param data [String] the GOBL value
275
+ #
276
+ # @return [CountryCode] the object created from the given data
277
+ def self.from_gobl!(data)
278
+ new(_value: data)
279
+ end
280
+
281
+ # Returns a GOBL value representing the current object
282
+ #
283
+ # @return [String] the GOBL value that represents the current object
284
+ def to_gobl
285
+ _value
286
+ end
287
+
288
+ # Returns a {CountryCode} that corresponds to a given object. The object can be a
289
+ # `Symbol`, a `String` or anything coercible into one (via `#to_s`).
290
+ #
291
+ # @param object [Symbol, String, #to_s] the value of the object.
292
+ #
293
+ # @return [CountryCode] the object corresponding to the given value.
294
+ #
295
+ # @example Instantiating from a symbol
296
+ # country_code = GOBL::L10n::CountryCode.new(:af)
297
+ #
298
+ # @example Instantiating from a string
299
+ # country_code = GOBL::L10n::CountryCode.new('AF')
300
+ def self.new(object)
301
+ case object
302
+ when Hash, self # internal use, not to be used in public calls
303
+ super
304
+ when Symbol
305
+ new find_by_sym(object)
306
+ else
307
+ super _value: object.to_s
308
+ end
309
+ end
310
+
311
+ # Returns the string representation of the current object
312
+ #
313
+ # @return [String] the string representation of the current object
314
+ def to_s
315
+ _value.to_s
316
+ end
317
+
318
+ # Returns the symbol representation of the current object
319
+ #
320
+ # @return [Symbol] the symbol representation of the current object
321
+ def to_sym
322
+ to_s.parameterize.underscore.to_sym
323
+ end
324
+
325
+ # Returns whether the current object is equivalent to a given one. In addition
326
+ # to {CountryCode} objects, the current object can be compared to a `Symbol`, a
327
+ # `String` or anything coercible into one (via `#to_s`)
328
+ #
329
+ # @param other [CountryCode, Symbol, String, #to_s] the other object to compare to
330
+ #
331
+ # @return [Boolean] `true` if the objects are equivalent, `false` otherwise
332
+ #
333
+ # @example Comparing to another {CountryCode} object
334
+ # country_code = GOBL::L10n::CountryCode.new('AF')
335
+ # country_code == GOBL::L10n::CountryCode.new('AF') #=> true
336
+ # country_code == GOBL::L10n::CountryCode.new('AX') #=> false
337
+ #
338
+ # @example Comparing to a string
339
+ # country_code = GOBL::L10n::CountryCode.new('AF')
340
+ # country_code == 'AF' #=> true
341
+ # country_code == 'AX' #=> false
342
+ #
343
+ # @example Comparing to a symbol
344
+ # country_code = GOBL::L10n::CountryCode.new('AF')
345
+ # country_code == :af #=> true
346
+ # country_code == :ax #=> false
347
+ def ==(other)
348
+ case other
349
+ when self.class
350
+ super
351
+ when Symbol
352
+ to_sym == other
353
+ else
354
+ to_s == other.to_s
355
+ end
356
+ end
357
+
358
+ # Returns an array with all the enumerated objects of this type
359
+ #
360
+ # @return [Array<CountryCode>] the array of enumerated objects
361
+ def self.all
362
+ ENUM.keys.map { |key| new(key) }
363
+ end
364
+
365
+ # @api private
366
+ def self.find_by_sym(sym)
367
+ all.find { |object| object.to_sym == sym }
368
+ end
369
+
370
+ # @api private
371
+ def self.find_by_inquirer(method_name)
372
+ method_name =~ /(.+)\?$/ && find_by_sym(Regexp.last_match(1).to_sym)
373
+ end
374
+
375
+ # Returns the description of the current object
376
+ #
377
+ # @return [String] the description of the current object
378
+ def description
379
+ ENUM.fetch(_value, _value)
380
+ end
381
+
382
+ # @api private
383
+ def respond_to_missing?(method_name, include_private = false)
384
+ self.class.find_by_inquirer(method_name) || super
385
+ end
386
+
387
+ # Enables dynamic value inquirers like `CountryCode#af?` for
388
+ # each of the declared enum values (see {ENUM}). Each inquirer returns a
389
+ # `Boolean` denoting whether the value equals the enquired value (`true`) or
390
+ # not (`false`)
391
+ #
392
+ # @example
393
+ # country_code = GOBL::L10n::CountryCode.new('AF')
394
+ # country_code.af? # => true
395
+ # country_code.ax? # => false
396
+ def method_missing(method_name, *args, &block)
397
+ if value = self.class.find_by_inquirer(method_name)
398
+ self == value
399
+ else
400
+ super
401
+ end
402
+ end
403
+ end
404
+ end
405
+ 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 Note
11
+ # Message represents the minimum possible contents for a GoBL document type.
12
+ class Message < GOBL::Struct
13
+ # The Schema ID of the GOBL Message structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/note/message'
15
+
16
+ # @!attribute [r] title
17
+ # Summary of the message content
18
+ # @return [String]
19
+ attribute? :title, GOBL::Types::String.optional
20
+
21
+ # @!attribute [r] content
22
+ # Details of what exactly this message wants to communicate
23
+ # @return [String]
24
+ attribute :content, GOBL::Types::String
25
+
26
+ # @!attribute [r] meta
27
+ # Any additional semi-structured data that might be useful.
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 [Message] the object created from the given data
36
+ def self.from_gobl!(data)
37
+ data = GOBL::Types::Hash[data]
38
+
39
+ new(
40
+ title: data['title'],
41
+ content: data['content'],
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
+ 'title' => attributes[:title],
52
+ 'content' => attributes[:content],
53
+ 'meta' => attributes[:meta]&.to_gobl
54
+ }.compact
55
+ end
56
+
57
+ # @!method self.new(attrs)
58
+ #
59
+ # Returns a {Message} 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 [Message] the object corresponding to the given input
70
+ end
71
+ end
72
+ end