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 Org
11
+ # Text identifier to be used instead of a code for a more verbose but readable identifier.
12
+ class Key < GOBL::Struct
13
+ # The Schema ID of the GOBL Key structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/key'
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 [Key] 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 {Key} 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 [Key] the object corresponding to the given value.
41
+ #
42
+ # @example Instantiating from a symbol
43
+ # key = GOBL::Org::Key.new(:value)
44
+ #
45
+ # @example Instantiating from a string
46
+ # key = GOBL::Org::Key.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 {Key} 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 [Key, 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 {Key} object
81
+ # key = GOBL::Org::Key.new('value')
82
+ # key == GOBL::Org::Key.new('value') #=> true
83
+ # key == GOBL::Org::Key.new('other') #=> false
84
+ #
85
+ # @example Comparing to a string
86
+ # key = GOBL::Org::Key.new('value')
87
+ # key == 'value' #=> true
88
+ # key == 'other' #=> false
89
+ #
90
+ # @example Comparing to a symbol
91
+ # key = GOBL::Org::Key.new('value')
92
+ # key == :value #=> true
93
+ # key == :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,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 Org
11
+ # Meta defines a structure for data about the data being defined.
12
+ class Meta < GOBL::Struct
13
+ extend Forwardable
14
+ include Enumerable
15
+
16
+ # The Schema ID of the GOBL Meta structure
17
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/meta'
18
+
19
+ attribute :_value, GOBL::Types::Hash
20
+
21
+ # @!method [](key)
22
+ # Returns the value associated with the given key
23
+ # @param key [Object] the key
24
+ # @return [Object] the value associated with the given key
25
+ #
26
+ # @!method each
27
+ # Iterates over each key-value pair in the map
28
+ # @overload each(&block)
29
+ # Calls the given block with each key-value pair in the map
30
+ # @yield [key, value] a key-value pair of the map
31
+ # @return [self] the object itself
32
+ # @overload each
33
+ # Returns an Enumerator that iterates over the key-value pairs in the map
34
+ # @return [Enumerator] the enumerator of the key-value pairs
35
+ #
36
+ # @!method empty?
37
+ # Returns `true` if the number of entires in the map is zero, `false` otherwise.
38
+ # @return [Boolean] whether the map is empty or not
39
+ #
40
+ # @!method length
41
+ # Returns the number of entries in the map
42
+ # @return [Integer] the number of entries in the map
43
+ #
44
+ # @!method each_key
45
+ # Iterates over each key in the map
46
+ # @overload each(&block)
47
+ # Calls the given block with each key in the map
48
+ # @yield [key] a key of the map
49
+ # @return [self] the object itself
50
+ # @overload each
51
+ # Returns an Enumerator that iterates over the keys in the map
52
+ # @return [Enumerator] the enumerator of the keys
53
+ def_delegators :_value, :[], :each, :empty?, :length, :each_key
54
+
55
+ # Creates a new object from a hash of GOBL data
56
+ #
57
+ # @param data [Hash] a hash of GOBL data
58
+ #
59
+ # @return [Meta] the object created from the given data
60
+ def self.from_gobl!(data)
61
+ new(_value: data)
62
+ end
63
+
64
+ # Returns a hash of GOBL data representing the current object
65
+ #
66
+ # @return [Hash] the hash of GOBL data that represents the current object
67
+ def to_gobl
68
+ _value
69
+ end
70
+ end
71
+ end
72
+ 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 Org
11
+ # Name represents what a human is called.
12
+ class Name < GOBL::Struct
13
+ # The Schema ID of the GOBL Name structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/name'
15
+
16
+ # @!attribute [r] uuid
17
+ # Unique identity code
18
+ # @return [GOBL::UUID::UUID]
19
+ attribute? :uuid, GOBL::UUID::UUID.optional
20
+
21
+ # @!attribute [r] alias
22
+ # What the person would like to be called
23
+ # @return [String]
24
+ attribute? :alias, GOBL::Types::String.optional
25
+
26
+ # @!attribute [r] prefix
27
+ # Additional prefix to add to name, like Mrs. or Mr.
28
+ # @return [String]
29
+ attribute? :prefix, GOBL::Types::String.optional
30
+
31
+ # @!attribute [r] given
32
+ # Person's given or first name
33
+ # @return [String]
34
+ attribute :given, GOBL::Types::String
35
+
36
+ # @!attribute [r] middle
37
+ # Middle names or initials
38
+ # @return [String]
39
+ attribute? :middle, GOBL::Types::String.optional
40
+
41
+ # @!attribute [r] surname
42
+ # Second or Family name.
43
+ # @return [String]
44
+ attribute :surname, GOBL::Types::String
45
+
46
+ # @!attribute [r] surname2
47
+ # Additional second of family name.
48
+ # @return [String]
49
+ attribute? :surname2, GOBL::Types::String.optional
50
+
51
+ # @!attribute [r] suffix
52
+ # Titles to include after the name.
53
+ # @return [String]
54
+ attribute? :suffix, GOBL::Types::String.optional
55
+
56
+ # @!attribute [r] meta
57
+ # Any additional useful data.
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 [Name] 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
+ alias: data['alias'],
72
+ prefix: data['prefix'],
73
+ given: data['given'],
74
+ middle: data['middle'],
75
+ surname: data['surname'],
76
+ surname2: data['surname2'],
77
+ suffix: data['suffix'],
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
+ 'alias' => attributes[:alias],
89
+ 'prefix' => attributes[:prefix],
90
+ 'given' => attributes[:given],
91
+ 'middle' => attributes[:middle],
92
+ 'surname' => attributes[:surname],
93
+ 'surname2' => attributes[:surname2],
94
+ 'suffix' => attributes[:suffix],
95
+ 'meta' => attributes[:meta]&.to_gobl
96
+ }.compact
97
+ end
98
+
99
+ # @!method self.new(attrs)
100
+ #
101
+ # Returns a {Name} 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 [Name] the object corresponding to the given input
112
+ end
113
+ end
114
+ 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 Org
11
+ # Note represents a free text of additional information that may be added to a document.
12
+ class Note < GOBL::Struct
13
+ # The Schema ID of the GOBL Note structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/note'
15
+
16
+ # @!attribute [r] key
17
+ # Key specifying subject of the text
18
+ # @return [NoteKey]
19
+ attribute? :key, NoteKey.optional
20
+
21
+ # @!attribute [r] code
22
+ # Code used for additional data that may be required to identify the note.
23
+ # @return [String]
24
+ attribute? :code, GOBL::Types::String.optional
25
+
26
+ # @!attribute [r] src
27
+ # Source of this note, especially useful when auto-generated.
28
+ # @return [String]
29
+ attribute? :src, GOBL::Types::String.optional
30
+
31
+ # @!attribute [r] text
32
+ # The contents of the note
33
+ # @return [String]
34
+ attribute :text, GOBL::Types::String
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 [Note] the object created from the given data
41
+ def self.from_gobl!(data)
42
+ data = GOBL::Types::Hash[data]
43
+
44
+ new(
45
+ key: data['key'] ? NoteKey.from_gobl!(data['key']) : nil,
46
+ code: data['code'],
47
+ src: data['src'],
48
+ text: data['text']
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
+ 'key' => attributes[:key]&.to_gobl,
58
+ 'code' => attributes[:code],
59
+ 'src' => attributes[:src],
60
+ 'text' => attributes[:text]
61
+ }.compact
62
+ end
63
+
64
+ # @!method self.new(attrs)
65
+ #
66
+ # Returns a {Note} 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 [Note] the object corresponding to the given input
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,181 @@
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 Org
11
+ # NoteKey identifies the type of note being edited
12
+ class NoteKey < GOBL::Struct
13
+ # The Schema ID of the GOBL NoteKey structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/note#/$defs/NoteKey'
15
+
16
+ # The enumeration of values of the object and their descriptions (Values different to these are not allowed)
17
+ ENUM = {
18
+ 'goods' => 'Goods Description',
19
+ 'payment' => 'Terms of Payment',
20
+ 'legal' => 'Legal or regulatory information',
21
+ 'dangerous-goods' => 'Dangerous goods additional information',
22
+ 'ack' => 'Acknowledgement Description',
23
+ 'rate' => 'Rate additional information',
24
+ 'reason' => 'Reason',
25
+ 'dispute' => 'Dispute',
26
+ 'customer' => 'Customer remarks',
27
+ 'glossary' => 'Glossary',
28
+ 'customs' => 'Customs declaration information',
29
+ 'general' => 'General information',
30
+ 'handling' => 'Handling instructions',
31
+ 'packaging' => 'Packaging information',
32
+ 'loading' => 'Loading instructions',
33
+ 'price' => 'Price conditions',
34
+ 'priority' => 'Priority information',
35
+ 'regulatory' => 'Regulatory information',
36
+ 'safety' => 'Safety instructions',
37
+ 'ship-line' => 'Ship line',
38
+ 'supplier' => 'Supplier remarks',
39
+ 'transport' => 'Transportation information',
40
+ 'delivery' => 'Delivery information',
41
+ 'quarantine' => 'Quarantine information',
42
+ 'tax' => 'Tax declaration'
43
+ }.freeze
44
+
45
+ attribute :_value, GOBL::Types::String.enum(*ENUM.keys)
46
+ private :_value
47
+
48
+ # Creates a new object from a GOBL value
49
+ #
50
+ # @param data [String] the GOBL value
51
+ #
52
+ # @return [NoteKey] the object created from the given data
53
+ def self.from_gobl!(data)
54
+ new(_value: data)
55
+ end
56
+
57
+ # Returns a GOBL value representing the current object
58
+ #
59
+ # @return [String] the GOBL value that represents the current object
60
+ def to_gobl
61
+ _value
62
+ end
63
+
64
+ # Returns a {NoteKey} that corresponds to a given object. The object can be a
65
+ # `Symbol`, a `String` or anything coercible into one (via `#to_s`).
66
+ #
67
+ # @param object [Symbol, String, #to_s] the value of the object.
68
+ #
69
+ # @return [NoteKey] the object corresponding to the given value.
70
+ #
71
+ # @example Instantiating from a symbol
72
+ # note_key = GOBL::Org::NoteKey.new(:goods)
73
+ #
74
+ # @example Instantiating from a string
75
+ # note_key = GOBL::Org::NoteKey.new('goods')
76
+ def self.new(object)
77
+ case object
78
+ when Hash, self # internal use, not to be used in public calls
79
+ super
80
+ when Symbol
81
+ new find_by_sym(object)
82
+ else
83
+ super _value: object.to_s
84
+ end
85
+ end
86
+
87
+ # Returns the string representation of the current object
88
+ #
89
+ # @return [String] the string representation of the current object
90
+ def to_s
91
+ _value.to_s
92
+ end
93
+
94
+ # Returns the symbol representation of the current object
95
+ #
96
+ # @return [Symbol] the symbol representation of the current object
97
+ def to_sym
98
+ to_s.parameterize.underscore.to_sym
99
+ end
100
+
101
+ # Returns whether the current object is equivalent to a given one. In addition
102
+ # to {NoteKey} objects, the current object can be compared to a `Symbol`, a
103
+ # `String` or anything coercible into one (via `#to_s`)
104
+ #
105
+ # @param other [NoteKey, Symbol, String, #to_s] the other object to compare to
106
+ #
107
+ # @return [Boolean] `true` if the objects are equivalent, `false` otherwise
108
+ #
109
+ # @example Comparing to another {NoteKey} object
110
+ # note_key = GOBL::Org::NoteKey.new('goods')
111
+ # note_key == GOBL::Org::NoteKey.new('goods') #=> true
112
+ # note_key == GOBL::Org::NoteKey.new('payment') #=> false
113
+ #
114
+ # @example Comparing to a string
115
+ # note_key = GOBL::Org::NoteKey.new('goods')
116
+ # note_key == 'goods' #=> true
117
+ # note_key == 'payment' #=> false
118
+ #
119
+ # @example Comparing to a symbol
120
+ # note_key = GOBL::Org::NoteKey.new('goods')
121
+ # note_key == :goods #=> true
122
+ # note_key == :payment #=> false
123
+ def ==(other)
124
+ case other
125
+ when self.class
126
+ super
127
+ when Symbol
128
+ to_sym == other
129
+ else
130
+ to_s == other.to_s
131
+ end
132
+ end
133
+
134
+ # Returns an array with all the enumerated objects of this type
135
+ #
136
+ # @return [Array<NoteKey>] the array of enumerated objects
137
+ def self.all
138
+ ENUM.keys.map { |key| new(key) }
139
+ end
140
+
141
+ # @api private
142
+ def self.find_by_sym(sym)
143
+ all.find { |object| object.to_sym == sym }
144
+ end
145
+
146
+ # @api private
147
+ def self.find_by_inquirer(method_name)
148
+ method_name =~ /(.+)\?$/ && find_by_sym(Regexp.last_match(1).to_sym)
149
+ end
150
+
151
+ # Returns the description of the current object
152
+ #
153
+ # @return [String] the description of the current object
154
+ def description
155
+ ENUM.fetch(_value, _value)
156
+ end
157
+
158
+ # @api private
159
+ def respond_to_missing?(method_name, include_private = false)
160
+ self.class.find_by_inquirer(method_name) || super
161
+ end
162
+
163
+ # Enables dynamic value inquirers like `NoteKey#goods?` for
164
+ # each of the declared enum values (see {ENUM}). Each inquirer returns a
165
+ # `Boolean` denoting whether the value equals the enquired value (`true`) or
166
+ # not (`false`)
167
+ #
168
+ # @example
169
+ # note_key = GOBL::Org::NoteKey.new('goods')
170
+ # note_key.goods? # => true
171
+ # note_key.payment? # => false
172
+ def method_missing(method_name, *args, &block)
173
+ if value = self.class.find_by_inquirer(method_name)
174
+ self == value
175
+ else
176
+ super
177
+ end
178
+ end
179
+ end
180
+ end
181
+ end
@@ -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 Org
11
+ # Party represents a person or business entity.
12
+ class Party < GOBL::Struct
13
+ # The Schema ID of the GOBL Party structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/party'
15
+
16
+ # @!attribute [r] id
17
+ # Internal ID used to identify the party inside a document.
18
+ # @return [String]
19
+ attribute? :id, GOBL::Types::String.optional
20
+
21
+ # @!attribute [r] uuid
22
+ # Unique identity code
23
+ # @return [GOBL::UUID::UUID]
24
+ attribute? :uuid, GOBL::UUID::UUID.optional
25
+
26
+ # @!attribute [r] tax_id
27
+ # The entity's legal ID code used for tax purposes. They may have other numbers, but we're only interested in those valid for tax purposes.
28
+ # @return [GOBL::Org::TaxIdentity]
29
+ attribute? :tax_id, GOBL::Org::TaxIdentity.optional
30
+
31
+ # @!attribute [r] name
32
+ # Legal name or representation of the organization.
33
+ # @return [String]
34
+ attribute :name, GOBL::Types::String
35
+
36
+ # @!attribute [r] alias
37
+ # Alternate short name.
38
+ # @return [String]
39
+ attribute? :alias, GOBL::Types::String.optional
40
+
41
+ # @!attribute [r] people
42
+ # Details of physical people who represent the party.
43
+ # @return [Array<GOBL::Org::Person>]
44
+ attribute? :people, GOBL::Types::Array.of(GOBL::Org::Person).optional
45
+
46
+ # @!attribute [r] inboxes
47
+ # Digital inboxes used for forwarding electronic versions of documents
48
+ # @return [Array<GOBL::Org::Inbox>]
49
+ attribute? :inboxes, GOBL::Types::Array.of(GOBL::Org::Inbox).optional
50
+
51
+ # @!attribute [r] addresses
52
+ # Regular post addresses for where information should be sent if needed.
53
+ # @return [Array<GOBL::Org::Address>]
54
+ attribute? :addresses, GOBL::Types::Array.of(GOBL::Org::Address).optional
55
+
56
+ # @!attribute [r] emails
57
+ # Electronic mail addresses
58
+ # @return [Array<GOBL::Org::Email>]
59
+ attribute? :emails, GOBL::Types::Array.of(GOBL::Org::Email).optional
60
+
61
+ # @!attribute [r] telephones
62
+ # Regular telephone numbers
63
+ # @return [Array<GOBL::Org::Telephone>]
64
+ attribute? :telephones, GOBL::Types::Array.of(GOBL::Org::Telephone).optional
65
+
66
+ # @!attribute [r] registration
67
+ # Additional registration details about the company that may need to be included in a document.
68
+ # @return [GOBL::Org::Registration]
69
+ attribute? :registration, GOBL::Org::Registration.optional
70
+
71
+ # @!attribute [r] meta
72
+ # Any additional semi-structured information that does not fit into the rest of the party.
73
+ # @return [GOBL::Org::Meta]
74
+ attribute? :meta, GOBL::Org::Meta.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 [Party] the object created from the given data
81
+ def self.from_gobl!(data)
82
+ data = GOBL::Types::Hash[data]
83
+
84
+ new(
85
+ id: data['id'],
86
+ uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
87
+ tax_id: data['tax_id'] ? GOBL::Org::TaxIdentity.from_gobl!(data['tax_id']) : nil,
88
+ name: data['name'],
89
+ alias: data['alias'],
90
+ people: data['people']&.map { |item| GOBL::Org::Person.from_gobl!(item) },
91
+ inboxes: data['inboxes']&.map { |item| GOBL::Org::Inbox.from_gobl!(item) },
92
+ addresses: data['addresses']&.map { |item| GOBL::Org::Address.from_gobl!(item) },
93
+ emails: data['emails']&.map { |item| GOBL::Org::Email.from_gobl!(item) },
94
+ telephones: data['telephones']&.map { |item| GOBL::Org::Telephone.from_gobl!(item) },
95
+ registration: data['registration'] ? GOBL::Org::Registration.from_gobl!(data['registration']) : nil,
96
+ meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : 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
+ 'id' => attributes[:id],
106
+ 'uuid' => attributes[:uuid]&.to_gobl,
107
+ 'tax_id' => attributes[:tax_id]&.to_gobl,
108
+ 'name' => attributes[:name],
109
+ 'alias' => attributes[:alias],
110
+ 'people' => attributes[:people]&.map { |item| item&.to_gobl },
111
+ 'inboxes' => attributes[:inboxes]&.map { |item| item&.to_gobl },
112
+ 'addresses' => attributes[:addresses]&.map { |item| item&.to_gobl },
113
+ 'emails' => attributes[:emails]&.map { |item| item&.to_gobl },
114
+ 'telephones' => attributes[:telephones]&.map { |item| item&.to_gobl },
115
+ 'registration' => attributes[:registration]&.to_gobl,
116
+ 'meta' => attributes[:meta]&.to_gobl
117
+ }.compact
118
+ end
119
+
120
+ # @!method self.new(attrs)
121
+ #
122
+ # Returns a {Party} 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 [Party] the object corresponding to the given input
133
+ end
134
+ end
135
+ end