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,135 @@
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
+ # Totals contains the summaries of all calculations for the invoice.
12
+ class Totals < GOBL::Struct
13
+ # The Schema ID of the GOBL Totals structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/bill/invoice#/$defs/Totals'
15
+
16
+ # @!attribute [r] sum
17
+ # Sum of all line item sums
18
+ # @return [GOBL::Num::Amount]
19
+ attribute :sum, GOBL::Types.Constructor(GOBL::Num::Amount)
20
+
21
+ # @!attribute [r] discount
22
+ # Sum of all document level discounts
23
+ # @return [GOBL::Num::Amount]
24
+ attribute? :discount, GOBL::Types.Constructor(GOBL::Num::Amount).optional
25
+
26
+ # @!attribute [r] charge
27
+ # Sum of all document level charges
28
+ # @return [GOBL::Num::Amount]
29
+ attribute? :charge, GOBL::Types.Constructor(GOBL::Num::Amount).optional
30
+
31
+ # @!attribute [r] tax_included
32
+ # If prices include tax, this is the total tax included in the price.
33
+ # @return [GOBL::Num::Amount]
34
+ attribute? :tax_included, GOBL::Types.Constructor(GOBL::Num::Amount).optional
35
+
36
+ # @!attribute [r] total
37
+ # Sum of all line sums minus the discounts, plus the charges, without tax.
38
+ # @return [GOBL::Num::Amount]
39
+ attribute :total, GOBL::Types.Constructor(GOBL::Num::Amount)
40
+
41
+ # @!attribute [r] taxes
42
+ # Summary of all the taxes included in the invoice.
43
+ # @return [GOBL::Tax::Total]
44
+ attribute? :taxes, GOBL::Tax::Total.optional
45
+
46
+ # @!attribute [r] tax
47
+ # Total amount of tax to apply to the invoice.
48
+ # @return [GOBL::Num::Amount]
49
+ attribute? :tax, GOBL::Types.Constructor(GOBL::Num::Amount).optional
50
+
51
+ # @!attribute [r] total_with_tax
52
+ # Grand total after all taxes have been applied.
53
+ # @return [GOBL::Num::Amount]
54
+ attribute :total_with_tax, GOBL::Types.Constructor(GOBL::Num::Amount)
55
+
56
+ # @!attribute [r] outlays
57
+ # Total paid in outlays that need to be reimbursed
58
+ # @return [GOBL::Num::Amount]
59
+ attribute? :outlays, GOBL::Types.Constructor(GOBL::Num::Amount).optional
60
+
61
+ # @!attribute [r] payable
62
+ # Total amount to be paid after applying taxes and outlays.
63
+ # @return [GOBL::Num::Amount]
64
+ attribute :payable, GOBL::Types.Constructor(GOBL::Num::Amount)
65
+
66
+ # @!attribute [r] advance
67
+ # Total amount already paid in advance.
68
+ # @return [GOBL::Num::Amount]
69
+ attribute? :advance, GOBL::Types.Constructor(GOBL::Num::Amount).optional
70
+
71
+ # @!attribute [r] due
72
+ # How much actually needs to be paid now.
73
+ # @return [GOBL::Num::Amount]
74
+ attribute? :due, GOBL::Types.Constructor(GOBL::Num::Amount).optional
75
+
76
+ # Creates a new object from a hash of GOBL data
77
+ #
78
+ # @param data [Hash] a hash of GOBL data
79
+ #
80
+ # @return [Totals] the object created from the given data
81
+ def self.from_gobl!(data)
82
+ data = GOBL::Types::Hash[data]
83
+
84
+ new(
85
+ sum: data['sum'],
86
+ discount: data['discount'] || nil,
87
+ charge: data['charge'] || nil,
88
+ tax_included: data['tax_included'] || nil,
89
+ total: data['total'],
90
+ taxes: data['taxes'] ? GOBL::Tax::Total.from_gobl!(data['taxes']) : nil,
91
+ tax: data['tax'] || nil,
92
+ total_with_tax: data['total_with_tax'],
93
+ outlays: data['outlays'] || nil,
94
+ payable: data['payable'],
95
+ advance: data['advance'] || nil,
96
+ due: data['due'] || nil
97
+ )
98
+ end
99
+
100
+ # Returns a hash of GOBL data representing the current object
101
+ #
102
+ # @return [Hash] the array of GOBL data that represents the current object
103
+ def to_gobl
104
+ {
105
+ 'sum' => attributes[:sum]&.to_gobl,
106
+ 'discount' => attributes[:discount]&.to_gobl,
107
+ 'charge' => attributes[:charge]&.to_gobl,
108
+ 'tax_included' => attributes[:tax_included]&.to_gobl,
109
+ 'total' => attributes[:total]&.to_gobl,
110
+ 'taxes' => attributes[:taxes]&.to_gobl,
111
+ 'tax' => attributes[:tax]&.to_gobl,
112
+ 'total_with_tax' => attributes[:total_with_tax]&.to_gobl,
113
+ 'outlays' => attributes[:outlays]&.to_gobl,
114
+ 'payable' => attributes[:payable]&.to_gobl,
115
+ 'advance' => attributes[:advance]&.to_gobl,
116
+ 'due' => attributes[:due]&.to_gobl
117
+ }.compact
118
+ end
119
+
120
+ # @!method self.new(attrs)
121
+ #
122
+ # Returns a {Totals} object from a given hash of attributes. Nested
123
+ # attributes are supported: the constructor will instantiate the proper GOBL
124
+ # objects when nested hashes or arrays are given as part of the `attrs`
125
+ # parameter.
126
+ #
127
+ # The `new` method will only allow to create a new object if all attributes
128
+ # marked as mandatory and not calculated in the JSON schema are provided.
129
+ #
130
+ # @param attrs [Hash] the hash of attributes
131
+ #
132
+ # @return [Totals] the object corresponding to the given input
133
+ end
134
+ end
135
+ end
@@ -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 Cal
11
+ # Civil date in simplified ISO format, like 2021-05-26
12
+ class Date < GOBL::Struct
13
+ # The Schema ID of the GOBL Date structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/cal/date'
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 [Date] 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 {Date} 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 [Date] the object corresponding to the given value.
41
+ #
42
+ # @example Instantiating from a symbol
43
+ # date = GOBL::Cal::Date.new(:value)
44
+ #
45
+ # @example Instantiating from a string
46
+ # date = GOBL::Cal::Date.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 {Date} 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 [Date, 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 {Date} object
81
+ # date = GOBL::Cal::Date.new('value')
82
+ # date == GOBL::Cal::Date.new('value') #=> true
83
+ # date == GOBL::Cal::Date.new('other') #=> false
84
+ #
85
+ # @example Comparing to a string
86
+ # date = GOBL::Cal::Date.new('value')
87
+ # date == 'value' #=> true
88
+ # date == 'other' #=> false
89
+ #
90
+ # @example Comparing to a symbol
91
+ # date = GOBL::Cal::Date.new('value')
92
+ # date == :value #=> true
93
+ # date == :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,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
+ module Cal
11
+ # Period represents two dates with a start and finish.
12
+ class Period < GOBL::Struct
13
+ # The Schema ID of the GOBL Period structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/cal/period'
15
+
16
+ # @!attribute [r] start
17
+ # @return [GOBL::Cal::Date]
18
+ attribute :start, GOBL::Cal::Date
19
+
20
+ # @!attribute [r] end
21
+ # @return [GOBL::Cal::Date]
22
+ attribute :end, GOBL::Cal::Date
23
+
24
+ # Creates a new object from a hash of GOBL data
25
+ #
26
+ # @param data [Hash] a hash of GOBL data
27
+ #
28
+ # @return [Period] the object created from the given data
29
+ def self.from_gobl!(data)
30
+ data = GOBL::Types::Hash[data]
31
+
32
+ new(
33
+ start: GOBL::Cal::Date.from_gobl!(data['start']),
34
+ end: GOBL::Cal::Date.from_gobl!(data['end'])
35
+ )
36
+ end
37
+
38
+ # Returns a hash of GOBL data representing the current object
39
+ #
40
+ # @return [Hash] the array of GOBL data that represents the current object
41
+ def to_gobl
42
+ {
43
+ 'start' => attributes[:start]&.to_gobl,
44
+ 'end' => attributes[:end]&.to_gobl
45
+ }.compact
46
+ end
47
+
48
+ # @!method self.new(attrs)
49
+ #
50
+ # Returns a {Period} object from a given hash of attributes. Nested
51
+ # attributes are supported: the constructor will instantiate the proper GOBL
52
+ # objects when nested hashes or arrays are given as part of the `attrs`
53
+ # parameter.
54
+ #
55
+ # The `new` method will only allow to create a new object if all attributes
56
+ # marked as mandatory and not calculated in the JSON schema are provided.
57
+ #
58
+ # @param attrs [Hash] the hash of attributes
59
+ #
60
+ # @return [Period] the object corresponding to the given input
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GOBL
4
+ # Provides accessors to the library's configuration settings
5
+ class Config
6
+ # The host of the GOBL CLI service to use by {GOBL::Operations}
7
+ # @return [String] the backend service's host
8
+ attr_accessor :service_host
9
+
10
+ # The port of the GOBL CLI service to use by {GOBL::Operations}
11
+ # @return [String, Integer] the backend service's port
12
+ attr_accessor :service_port
13
+ end
14
+ end
@@ -0,0 +1,322 @@
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 Currency
11
+ # ISO Currency Code
12
+ class Code < GOBL::Struct
13
+ # The Schema ID of the GOBL Code structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/currency/code'
15
+
16
+ # The enumeration of values of the object and their descriptions (Values different to these are not allowed)
17
+ ENUM = {
18
+ 'AED' => 'UAE Dirham',
19
+ 'AFN' => 'Afghani',
20
+ 'ALL' => 'Lek',
21
+ 'AMD' => 'Armenian Dram',
22
+ 'ANG' => 'Netherlands Antillean Guilder',
23
+ 'AOA' => 'Kwanza',
24
+ 'ARS' => 'Argentine Peso',
25
+ 'AUD' => 'Australian Dollar',
26
+ 'AWG' => 'Aruban Florin',
27
+ 'AZN' => 'Azerbaijan Manat',
28
+ 'BAM' => 'Convertible Mark',
29
+ 'BBD' => 'Barbados Dollar',
30
+ 'BDT' => 'Taka',
31
+ 'BGN' => 'Bulgarian Lev',
32
+ 'BHD' => 'Bahraini Dinar',
33
+ 'BIF' => 'Burundi Franc',
34
+ 'BMD' => 'Bermudian Dollar',
35
+ 'BND' => 'Brunei Dollar',
36
+ 'BOB' => 'Boliviano',
37
+ 'BOV' => 'Mvdol',
38
+ 'BRL' => 'Brazilian Real',
39
+ 'BSD' => 'Bahamian Dollar',
40
+ 'BTN' => 'Ngultrum',
41
+ 'BWP' => 'Pula',
42
+ 'BYN' => 'Belarusian Ruble',
43
+ 'BZD' => 'Belize Dollar',
44
+ 'CAD' => 'Canadian Dollar',
45
+ 'CDF' => 'Congolese Franc',
46
+ 'CHE' => 'WIR Euro',
47
+ 'CHF' => 'Swiss Franc',
48
+ 'CHW' => 'WIR Franc',
49
+ 'CLF' => 'Unidad de Fomento',
50
+ 'CLP' => 'Chilean Peso',
51
+ 'CNY' => 'Yuan Renminbi',
52
+ 'COP' => 'Colombian Peso',
53
+ 'COU' => 'Unidad de Valor Real',
54
+ 'CRC' => 'Costa Rican Colon',
55
+ 'CUC' => 'Peso Convertible',
56
+ 'CUP' => 'Cuban Peso',
57
+ 'CVE' => 'Cabo Verde Escudo',
58
+ 'CZK' => 'Czech Koruna',
59
+ 'DJF' => 'Djibouti Franc',
60
+ 'DKK' => 'Danish Krone',
61
+ 'DOP' => 'Dominican Peso',
62
+ 'DZD' => 'Algerian Dinar',
63
+ 'EGP' => 'Egyptian Pound',
64
+ 'ERN' => 'Nakfa',
65
+ 'ETB' => 'Ethiopian Birr',
66
+ 'EUR' => 'Euro',
67
+ 'FJD' => 'Fiji Dollar',
68
+ 'FKP' => 'Falkland Islands Pound',
69
+ 'GBP' => 'Pound Sterling',
70
+ 'GEL' => 'Lari',
71
+ 'GHS' => 'Ghana Cedi',
72
+ 'GIP' => 'Gibraltar Pound',
73
+ 'GMD' => 'Dalasi',
74
+ 'GNF' => 'Guinean Franc',
75
+ 'GTQ' => 'Quetzal',
76
+ 'GYD' => 'Guyana Dollar',
77
+ 'HKD' => 'Hong Kong Dollar',
78
+ 'HNL' => 'Lempira',
79
+ 'HRK' => 'Kuna',
80
+ 'HTG' => 'Gourde',
81
+ 'HUF' => 'Forint',
82
+ 'IDR' => 'Rupiah',
83
+ 'ILS' => 'New Israeli Sheqel',
84
+ 'INR' => 'Indian Rupee',
85
+ 'IQD' => 'Iraqi Dinar',
86
+ 'IRR' => 'Iranian Rial',
87
+ 'ISK' => 'Iceland Krona',
88
+ 'JMD' => 'Jamaican Dollar',
89
+ 'JOD' => 'Jordanian Dinar',
90
+ 'JPY' => 'Yen',
91
+ 'KES' => 'Kenyan Shilling',
92
+ 'KGS' => 'Som',
93
+ 'KHR' => 'Riel',
94
+ 'KMF' => 'Comorian Franc ',
95
+ 'KPW' => 'North Korean Won',
96
+ 'KRW' => 'Won',
97
+ 'KWD' => 'Kuwaiti Dinar',
98
+ 'KYD' => 'Cayman Islands Dollar',
99
+ 'KZT' => 'Tenge',
100
+ 'LAK' => 'Lao Kip',
101
+ 'LBP' => 'Lebanese Pound',
102
+ 'LKR' => 'Sri Lanka Rupee',
103
+ 'LRD' => 'Liberian Dollar',
104
+ 'LSL' => 'Loti',
105
+ 'LYD' => 'Libyan Dinar',
106
+ 'MAD' => 'Moroccan Dirham',
107
+ 'MDL' => 'Moldovan Leu',
108
+ 'MGA' => 'Malagasy Ariary',
109
+ 'MKD' => 'Denar',
110
+ 'MMK' => 'Kyat',
111
+ 'MNT' => 'Tugrik',
112
+ 'MOP' => 'Pataca',
113
+ 'MRU' => 'Ouguiya',
114
+ 'MUR' => 'Mauritius Rupee',
115
+ 'MVR' => 'Rufiyaa',
116
+ 'MWK' => 'Malawi Kwacha',
117
+ 'MXN' => 'Mexican Peso',
118
+ 'MXV' => 'Mexican Unidad de Inversion (UDI)',
119
+ 'MYR' => 'Malaysian Ringgit',
120
+ 'MZN' => 'Mozambique Metical',
121
+ 'NAD' => 'Namibia Dollar',
122
+ 'NGN' => 'Naira',
123
+ 'NIO' => 'Cordoba Oro',
124
+ 'NOK' => 'Norwegian Krone',
125
+ 'NPR' => 'Nepalese Rupee',
126
+ 'NZD' => 'New Zealand Dollar',
127
+ 'OMR' => 'Rial Omani',
128
+ 'PAB' => 'Balboa',
129
+ 'PEN' => 'Sol',
130
+ 'PGK' => 'Kina',
131
+ 'PHP' => 'Philippine Peso',
132
+ 'PKR' => 'Pakistan Rupee',
133
+ 'PLN' => 'Zloty',
134
+ 'PYG' => 'Guarani',
135
+ 'QAR' => 'Qatari Rial',
136
+ 'RON' => 'Romanian Leu',
137
+ 'RSD' => 'Serbian Dinar',
138
+ 'RUB' => 'Russian Ruble',
139
+ 'RWF' => 'Rwanda Franc',
140
+ 'SAR' => 'Saudi Riyal',
141
+ 'SBD' => 'Solomon Islands Dollar',
142
+ 'SCR' => 'Seychelles Rupee',
143
+ 'SDG' => 'Sudanese Pound',
144
+ 'SEK' => 'Swedish Krona',
145
+ 'SGD' => 'Singapore Dollar',
146
+ 'SHP' => 'Saint Helena Pound',
147
+ 'SLL' => 'Leone',
148
+ 'SOS' => 'Somali Shilling',
149
+ 'SRD' => 'Surinam Dollar',
150
+ 'SSP' => 'South Sudanese Pound',
151
+ 'STN' => 'Dobra',
152
+ 'SVC' => 'El Salvador Colon',
153
+ 'SYP' => 'Syrian Pound',
154
+ 'SZL' => 'Lilangeni',
155
+ 'THB' => 'Baht',
156
+ 'TJS' => 'Somoni',
157
+ 'TMT' => 'Turkmenistan New Manat',
158
+ 'TND' => 'Tunisian Dinar',
159
+ 'TOP' => 'Pa’anga',
160
+ 'TRY' => 'Turkish Lira',
161
+ 'TTD' => 'Trinidad and Tobago Dollar',
162
+ 'TWD' => 'New Taiwan Dollar',
163
+ 'TZS' => 'Tanzanian Shilling',
164
+ 'UAH' => 'Hryvnia',
165
+ 'UGX' => 'Uganda Shilling',
166
+ 'USD' => 'US Dollar',
167
+ 'USN' => 'US Dollar (Next day)',
168
+ 'UYI' => 'Uruguay Peso en Unidades Indexadas (UI)',
169
+ 'UYU' => 'Peso Uruguayo',
170
+ 'UYW' => 'Unidad Previsional',
171
+ 'UZS' => 'Uzbekistan Sum',
172
+ 'VES' => 'Bolívar Soberano',
173
+ 'VND' => 'Dong',
174
+ 'VUV' => 'Vatu',
175
+ 'WST' => 'Tala',
176
+ 'XAF' => 'CFA Franc BEAC',
177
+ 'XCD' => 'East Caribbean Dollar',
178
+ 'XOF' => 'CFA Franc BCEAO',
179
+ 'XPF' => 'CFP Franc',
180
+ 'YER' => 'Yemeni Rial',
181
+ 'ZAR' => 'Rand',
182
+ 'ZMW' => 'Zambian Kwacha',
183
+ 'ZWL' => 'Zimbabwe Dollar'
184
+ }.freeze
185
+
186
+ attribute :_value, GOBL::Types::String.enum(*ENUM.keys)
187
+ private :_value
188
+
189
+ # Creates a new object from a GOBL value
190
+ #
191
+ # @param data [String] the GOBL value
192
+ #
193
+ # @return [Code] the object created from the given data
194
+ def self.from_gobl!(data)
195
+ new(_value: data)
196
+ end
197
+
198
+ # Returns a GOBL value representing the current object
199
+ #
200
+ # @return [String] the GOBL value that represents the current object
201
+ def to_gobl
202
+ _value
203
+ end
204
+
205
+ # Returns a {Code} that corresponds to a given object. The object can be a
206
+ # `Symbol`, a `String` or anything coercible into one (via `#to_s`).
207
+ #
208
+ # @param object [Symbol, String, #to_s] the value of the object.
209
+ #
210
+ # @return [Code] the object corresponding to the given value.
211
+ #
212
+ # @example Instantiating from a symbol
213
+ # code = GOBL::Currency::Code.new(:aed)
214
+ #
215
+ # @example Instantiating from a string
216
+ # code = GOBL::Currency::Code.new('AED')
217
+ def self.new(object)
218
+ case object
219
+ when Hash, self # internal use, not to be used in public calls
220
+ super
221
+ when Symbol
222
+ new find_by_sym(object)
223
+ else
224
+ super _value: object.to_s
225
+ end
226
+ end
227
+
228
+ # Returns the string representation of the current object
229
+ #
230
+ # @return [String] the string representation of the current object
231
+ def to_s
232
+ _value.to_s
233
+ end
234
+
235
+ # Returns the symbol representation of the current object
236
+ #
237
+ # @return [Symbol] the symbol representation of the current object
238
+ def to_sym
239
+ to_s.parameterize.underscore.to_sym
240
+ end
241
+
242
+ # Returns whether the current object is equivalent to a given one. In addition
243
+ # to {Code} objects, the current object can be compared to a `Symbol`, a
244
+ # `String` or anything coercible into one (via `#to_s`)
245
+ #
246
+ # @param other [Code, Symbol, String, #to_s] the other object to compare to
247
+ #
248
+ # @return [Boolean] `true` if the objects are equivalent, `false` otherwise
249
+ #
250
+ # @example Comparing to another {Code} object
251
+ # code = GOBL::Currency::Code.new('AED')
252
+ # code == GOBL::Currency::Code.new('AED') #=> true
253
+ # code == GOBL::Currency::Code.new('AFN') #=> false
254
+ #
255
+ # @example Comparing to a string
256
+ # code = GOBL::Currency::Code.new('AED')
257
+ # code == 'AED' #=> true
258
+ # code == 'AFN' #=> false
259
+ #
260
+ # @example Comparing to a symbol
261
+ # code = GOBL::Currency::Code.new('AED')
262
+ # code == :aed #=> true
263
+ # code == :afn #=> false
264
+ def ==(other)
265
+ case other
266
+ when self.class
267
+ super
268
+ when Symbol
269
+ to_sym == other
270
+ else
271
+ to_s == other.to_s
272
+ end
273
+ end
274
+
275
+ # Returns an array with all the enumerated objects of this type
276
+ #
277
+ # @return [Array<Code>] the array of enumerated objects
278
+ def self.all
279
+ ENUM.keys.map { |key| new(key) }
280
+ end
281
+
282
+ # @api private
283
+ def self.find_by_sym(sym)
284
+ all.find { |object| object.to_sym == sym }
285
+ end
286
+
287
+ # @api private
288
+ def self.find_by_inquirer(method_name)
289
+ method_name =~ /(.+)\?$/ && find_by_sym(Regexp.last_match(1).to_sym)
290
+ end
291
+
292
+ # Returns the description of the current object
293
+ #
294
+ # @return [String] the description of the current object
295
+ def description
296
+ ENUM.fetch(_value, _value)
297
+ end
298
+
299
+ # @api private
300
+ def respond_to_missing?(method_name, include_private = false)
301
+ self.class.find_by_inquirer(method_name) || super
302
+ end
303
+
304
+ # Enables dynamic value inquirers like `Code#aed?` for
305
+ # each of the declared enum values (see {ENUM}). Each inquirer returns a
306
+ # `Boolean` denoting whether the value equals the enquired value (`true`) or
307
+ # not (`false`)
308
+ #
309
+ # @example
310
+ # code = GOBL::Currency::Code.new('AED')
311
+ # code.aed? # => true
312
+ # code.afn? # => false
313
+ def method_missing(method_name, *args, &block)
314
+ if value = self.class.find_by_inquirer(method_name)
315
+ self == value
316
+ else
317
+ super
318
+ end
319
+ end
320
+ end
321
+ end
322
+ end