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,156 @@
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
+ # Address defines a globally acceptable set of attributes that describes a postal or fiscal address.
12
+ class Address < GOBL::Struct
13
+ # The Schema ID of the GOBL Address structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/address'
15
+
16
+ # @!attribute [r] uuid
17
+ # Internal ID used to identify the party inside a document.
18
+ # @return [GOBL::UUID::UUID]
19
+ attribute? :uuid, GOBL::UUID::UUID.optional
20
+
21
+ # @!attribute [r] label
22
+ # Useful identifier, such as home, work, etc.
23
+ # @return [String]
24
+ attribute? :label, GOBL::Types::String.optional
25
+
26
+ # @!attribute [r] po_box
27
+ # Box number or code for the post office box located at the address.
28
+ # @return [String]
29
+ attribute? :po_box, GOBL::Types::String.optional
30
+
31
+ # @!attribute [r] num
32
+ # House or building number in the street.
33
+ # @return [String]
34
+ attribute? :num, GOBL::Types::String.optional
35
+
36
+ # @!attribute [r] floor
37
+ # Floor number within the building.
38
+ # @return [String]
39
+ attribute? :floor, GOBL::Types::String.optional
40
+
41
+ # @!attribute [r] block
42
+ # Block number within the building.
43
+ # @return [String]
44
+ attribute? :block, GOBL::Types::String.optional
45
+
46
+ # @!attribute [r] door
47
+ # Door number within the building.
48
+ # @return [String]
49
+ attribute? :door, GOBL::Types::String.optional
50
+
51
+ # @!attribute [r] street
52
+ # First line of street.
53
+ # @return [String]
54
+ attribute? :street, GOBL::Types::String.optional
55
+
56
+ # @!attribute [r] street_extra
57
+ # Additional street address details.
58
+ # @return [String]
59
+ attribute? :street_extra, GOBL::Types::String.optional
60
+
61
+ # @!attribute [r] locality
62
+ # The village, town, district, or city.
63
+ # @return [String]
64
+ attribute :locality, GOBL::Types::String
65
+
66
+ # @!attribute [r] region
67
+ # Province, County, or State.
68
+ # @return [String]
69
+ attribute :region, GOBL::Types::String
70
+
71
+ # @!attribute [r] code
72
+ # Post or ZIP code.
73
+ # @return [String]
74
+ attribute? :code, GOBL::Types::String.optional
75
+
76
+ # @!attribute [r] country
77
+ # ISO country code.
78
+ # @return [GOBL::L10n::CountryCode]
79
+ attribute? :country, GOBL::L10n::CountryCode.optional
80
+
81
+ # @!attribute [r] coords
82
+ # When the postal address is not sufficient, coordinates help locate the address more precisely.
83
+ # @return [GOBL::Org::Coordinates]
84
+ attribute? :coords, GOBL::Org::Coordinates.optional
85
+
86
+ # @!attribute [r] meta
87
+ # Any additional semi-structure details about the address.
88
+ # @return [GOBL::Org::Meta]
89
+ attribute? :meta, GOBL::Org::Meta.optional
90
+
91
+ # Creates a new object from a hash of GOBL data
92
+ #
93
+ # @param data [Hash] a hash of GOBL data
94
+ #
95
+ # @return [Address] the object created from the given data
96
+ def self.from_gobl!(data)
97
+ data = GOBL::Types::Hash[data]
98
+
99
+ new(
100
+ uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
101
+ label: data['label'],
102
+ po_box: data['po_box'],
103
+ num: data['num'],
104
+ floor: data['floor'],
105
+ block: data['block'],
106
+ door: data['door'],
107
+ street: data['street'],
108
+ street_extra: data['street_extra'],
109
+ locality: data['locality'],
110
+ region: data['region'],
111
+ code: data['code'],
112
+ country: data['country'] ? GOBL::L10n::CountryCode.from_gobl!(data['country']) : nil,
113
+ coords: data['coords'] ? GOBL::Org::Coordinates.from_gobl!(data['coords']) : nil,
114
+ meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
115
+ )
116
+ end
117
+
118
+ # Returns a hash of GOBL data representing the current object
119
+ #
120
+ # @return [Hash] the array of GOBL data that represents the current object
121
+ def to_gobl
122
+ {
123
+ 'uuid' => attributes[:uuid]&.to_gobl,
124
+ 'label' => attributes[:label],
125
+ 'po_box' => attributes[:po_box],
126
+ 'num' => attributes[:num],
127
+ 'floor' => attributes[:floor],
128
+ 'block' => attributes[:block],
129
+ 'door' => attributes[:door],
130
+ 'street' => attributes[:street],
131
+ 'street_extra' => attributes[:street_extra],
132
+ 'locality' => attributes[:locality],
133
+ 'region' => attributes[:region],
134
+ 'code' => attributes[:code],
135
+ 'country' => attributes[:country]&.to_gobl,
136
+ 'coords' => attributes[:coords]&.to_gobl,
137
+ 'meta' => attributes[:meta]&.to_gobl
138
+ }.compact
139
+ end
140
+
141
+ # @!method self.new(attrs)
142
+ #
143
+ # Returns a {Address} object from a given hash of attributes. Nested
144
+ # attributes are supported: the constructor will instantiate the proper GOBL
145
+ # objects when nested hashes or arrays are given as part of the `attrs`
146
+ # parameter.
147
+ #
148
+ # The `new` method will only allow to create a new object if all attributes
149
+ # marked as mandatory and not calculated in the JSON schema are provided.
150
+ #
151
+ # @param attrs [Hash] the hash of attributes
152
+ #
153
+ # @return [Address] the object corresponding to the given input
154
+ end
155
+ end
156
+ 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 Org
11
+ # Short upper-case identifier.
12
+ class Code < GOBL::Struct
13
+ # The Schema ID of the GOBL Code structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/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::Org::Code.new(:value)
44
+ #
45
+ # @example Instantiating from a string
46
+ # code = GOBL::Org::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::Org::Code.new('value')
82
+ # code == GOBL::Org::Code.new('value') #=> true
83
+ # code == GOBL::Org::Code.new('other') #=> false
84
+ #
85
+ # @example Comparing to a string
86
+ # code = GOBL::Org::Code.new('value')
87
+ # code == 'value' #=> true
88
+ # code == 'other' #=> false
89
+ #
90
+ # @example Comparing to a symbol
91
+ # code = GOBL::Org::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,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
+ # Coordinates describes an exact geographical location in the world.
12
+ class Coordinates < GOBL::Struct
13
+ # The Schema ID of the GOBL Coordinates structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/coordinates'
15
+
16
+ # @!attribute [r] lat
17
+ # Decimal latitude coordinate.
18
+ # @return [Float]
19
+ attribute? :lat, GOBL::Types::Double.optional
20
+
21
+ # @!attribute [r] lon
22
+ # Decimal longitude coordinate.
23
+ # @return [Float]
24
+ attribute? :lon, GOBL::Types::Double.optional
25
+
26
+ # @!attribute [r] w3w
27
+ # Text coordinates compose of three words.
28
+ # @return [String]
29
+ attribute? :w3w, GOBL::Types::String.optional
30
+
31
+ # @!attribute [r] geohash
32
+ # Single string coordinate based on geohash standard.
33
+ # @return [String]
34
+ attribute? :geohash, 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 [Coordinates] the object created from the given data
41
+ def self.from_gobl!(data)
42
+ data = GOBL::Types::Hash[data]
43
+
44
+ new(
45
+ lat: data['lat'],
46
+ lon: data['lon'],
47
+ w3w: data['w3w'],
48
+ geohash: data['geohash']
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
+ 'lat' => attributes[:lat],
58
+ 'lon' => attributes[:lon],
59
+ 'w3w' => attributes[:w3w],
60
+ 'geohash' => attributes[:geohash]
61
+ }.compact
62
+ end
63
+
64
+ # @!method self.new(attrs)
65
+ #
66
+ # Returns a {Coordinates} 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 [Coordinates] the object corresponding to the given input
77
+ end
78
+ end
79
+ 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
+ # Email describes the electronic mailing details.
12
+ class Email < GOBL::Struct
13
+ # The Schema ID of the GOBL Email structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/email'
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] label
22
+ # Identifier for the email.
23
+ # @return [String]
24
+ attribute? :label, GOBL::Types::String.optional
25
+
26
+ # @!attribute [r] addr
27
+ # Electronic mailing address.
28
+ # @return [String]
29
+ attribute :addr, GOBL::Types::String
30
+
31
+ # @!attribute [r] meta
32
+ # Additional fields.
33
+ # @return [GOBL::Org::Meta]
34
+ attribute? :meta, GOBL::Org::Meta.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 [Email] the object created from the given data
41
+ def self.from_gobl!(data)
42
+ data = GOBL::Types::Hash[data]
43
+
44
+ new(
45
+ uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
46
+ label: data['label'],
47
+ addr: data['addr'],
48
+ meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : 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
+ 'uuid' => attributes[:uuid]&.to_gobl,
58
+ 'label' => attributes[:label],
59
+ 'addr' => attributes[:addr],
60
+ 'meta' => attributes[:meta]&.to_gobl
61
+ }.compact
62
+ end
63
+
64
+ # @!method self.new(attrs)
65
+ #
66
+ # Returns a {Email} 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 [Email] the object corresponding to the given input
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,86 @@
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
+ # Inbox is used to store data about a connection with a service that is responsible for potentially receiving copies of GOBL envelopes or other document formats defined locally.
12
+ class Inbox < GOBL::Struct
13
+ # The Schema ID of the GOBL Inbox structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/inbox'
15
+
16
+ # @!attribute [r] uuid
17
+ # Unique ID. Useful if inbox is stored in a database.
18
+ # @return [GOBL::UUID::UUID]
19
+ attribute? :uuid, GOBL::UUID::UUID.optional
20
+
21
+ # @!attribute [r] key
22
+ # Type of inbox being defined.
23
+ # @return [GOBL::Org::Key]
24
+ attribute :key, GOBL::Org::Key
25
+
26
+ # @!attribute [r] role
27
+ # Role assigned to this inbox that may be relevant for the consumer.
28
+ # @return [GOBL::Org::Key]
29
+ attribute? :role, GOBL::Org::Key.optional
30
+
31
+ # @!attribute [r] name
32
+ # Human name for the inbox.
33
+ # @return [String]
34
+ attribute? :name, GOBL::Types::String.optional
35
+
36
+ # @!attribute [r] code
37
+ # Actual Code or ID that identifies the Inbox.
38
+ # @return [String]
39
+ attribute :code, GOBL::Types::String
40
+
41
+ # Creates a new object from a hash of GOBL data
42
+ #
43
+ # @param data [Hash] a hash of GOBL data
44
+ #
45
+ # @return [Inbox] the object created from the given data
46
+ def self.from_gobl!(data)
47
+ data = GOBL::Types::Hash[data]
48
+
49
+ new(
50
+ uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
51
+ key: GOBL::Org::Key.from_gobl!(data['key']),
52
+ role: data['role'] ? GOBL::Org::Key.from_gobl!(data['role']) : nil,
53
+ name: data['name'],
54
+ code: data['code']
55
+ )
56
+ end
57
+
58
+ # Returns a hash of GOBL data representing the current object
59
+ #
60
+ # @return [Hash] the array of GOBL data that represents the current object
61
+ def to_gobl
62
+ {
63
+ 'uuid' => attributes[:uuid]&.to_gobl,
64
+ 'key' => attributes[:key]&.to_gobl,
65
+ 'role' => attributes[:role]&.to_gobl,
66
+ 'name' => attributes[:name],
67
+ 'code' => attributes[:code]
68
+ }.compact
69
+ end
70
+
71
+ # @!method self.new(attrs)
72
+ #
73
+ # Returns a {Inbox} object from a given hash of attributes. Nested
74
+ # attributes are supported: the constructor will instantiate the proper GOBL
75
+ # objects when nested hashes or arrays are given as part of the `attrs`
76
+ # parameter.
77
+ #
78
+ # The `new` method will only allow to create a new object if all attributes
79
+ # marked as mandatory and not calculated in the JSON schema are provided.
80
+ #
81
+ # @param attrs [Hash] the hash of attributes
82
+ #
83
+ # @return [Inbox] the object corresponding to the given input
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,121 @@
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
+ # Item is used to describe a single product or service.
12
+ class Item < GOBL::Struct
13
+ # The Schema ID of the GOBL Item structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/item'
15
+
16
+ # @!attribute [r] uuid
17
+ # Unique identify of this item independent of the Supplier IDs
18
+ # @return [GOBL::UUID::UUID]
19
+ attribute? :uuid, GOBL::UUID::UUID.optional
20
+
21
+ # @!attribute [r] ref
22
+ # Primary reference code that identifies this item. Additional codes can be provided in the 'codes' field.
23
+ # @return [String]
24
+ attribute? :ref, GOBL::Types::String.optional
25
+
26
+ # @!attribute [r] name
27
+ # Brief name of the item
28
+ # @return [String]
29
+ attribute :name, GOBL::Types::String
30
+
31
+ # @!attribute [r] desc
32
+ # Detailed description
33
+ # @return [String]
34
+ attribute? :desc, GOBL::Types::String.optional
35
+
36
+ # @!attribute [r] currency
37
+ # Currency used for the item's price.
38
+ # @return [String]
39
+ attribute? :currency, GOBL::Types::String.optional
40
+
41
+ # @!attribute [r] price
42
+ # Base price of a single unit to be sold.
43
+ # @return [GOBL::Num::Amount]
44
+ attribute :price, GOBL::Types.Constructor(GOBL::Num::Amount)
45
+
46
+ # @!attribute [r] unit
47
+ # Unit of measure.
48
+ # @return [GOBL::Org::Unit]
49
+ attribute? :unit, GOBL::Org::Unit.optional
50
+
51
+ # @!attribute [r] codes
52
+ # List of additional codes, IDs, or SKUs which can be used to identify the item. The should be agreed upon between supplier and customer.
53
+ # @return [Array<ItemCode>]
54
+ attribute? :codes, GOBL::Types::Array.of(ItemCode).optional
55
+
56
+ # @!attribute [r] origin
57
+ # Country code of where this item was from originally.
58
+ # @return [GOBL::L10n::CountryCode]
59
+ attribute? :origin, GOBL::L10n::CountryCode.optional
60
+
61
+ # @!attribute [r] meta
62
+ # Additional meta information that may be useful
63
+ # @return [GOBL::Org::Meta]
64
+ attribute? :meta, GOBL::Org::Meta.optional
65
+
66
+ # Creates a new object from a hash of GOBL data
67
+ #
68
+ # @param data [Hash] a hash of GOBL data
69
+ #
70
+ # @return [Item] the object created from the given data
71
+ def self.from_gobl!(data)
72
+ data = GOBL::Types::Hash[data]
73
+
74
+ new(
75
+ uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
76
+ ref: data['ref'],
77
+ name: data['name'],
78
+ desc: data['desc'],
79
+ currency: data['currency'],
80
+ price: data['price'],
81
+ unit: data['unit'] ? GOBL::Org::Unit.from_gobl!(data['unit']) : nil,
82
+ codes: data['codes']&.map { |item| ItemCode.from_gobl!(item) },
83
+ origin: data['origin'] ? GOBL::L10n::CountryCode.from_gobl!(data['origin']) : nil,
84
+ meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
85
+ )
86
+ end
87
+
88
+ # Returns a hash of GOBL data representing the current object
89
+ #
90
+ # @return [Hash] the array of GOBL data that represents the current object
91
+ def to_gobl
92
+ {
93
+ 'uuid' => attributes[:uuid]&.to_gobl,
94
+ 'ref' => attributes[:ref],
95
+ 'name' => attributes[:name],
96
+ 'desc' => attributes[:desc],
97
+ 'currency' => attributes[:currency],
98
+ 'price' => attributes[:price]&.to_gobl,
99
+ 'unit' => attributes[:unit]&.to_gobl,
100
+ 'codes' => attributes[:codes]&.map { |item| item&.to_gobl },
101
+ 'origin' => attributes[:origin]&.to_gobl,
102
+ 'meta' => attributes[:meta]&.to_gobl
103
+ }.compact
104
+ end
105
+
106
+ # @!method self.new(attrs)
107
+ #
108
+ # Returns a {Item} object from a given hash of attributes. Nested
109
+ # attributes are supported: the constructor will instantiate the proper GOBL
110
+ # objects when nested hashes or arrays are given as part of the `attrs`
111
+ # parameter.
112
+ #
113
+ # The `new` method will only allow to create a new object if all attributes
114
+ # marked as mandatory and not calculated in the JSON schema are provided.
115
+ #
116
+ # @param attrs [Hash] the hash of attributes
117
+ #
118
+ # @return [Item] the object corresponding to the given input
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,65 @@
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
+ # ItemCode contains a value and optional label property that means additional codes can be added to an item.
12
+ class ItemCode < GOBL::Struct
13
+ # The Schema ID of the GOBL ItemCode structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/org/item#/$defs/ItemCode'
15
+
16
+ # @!attribute [r] label
17
+ # Local or human reference for the type of code the value represents.
18
+ # @return [String]
19
+ attribute? :label, GOBL::Types::String.optional
20
+
21
+ # @!attribute [r] value
22
+ # The item code's value.
23
+ # @return [String]
24
+ attribute :value, GOBL::Types::String
25
+
26
+ # Creates a new object from a hash of GOBL data
27
+ #
28
+ # @param data [Hash] a hash of GOBL data
29
+ #
30
+ # @return [ItemCode] the object created from the given data
31
+ def self.from_gobl!(data)
32
+ data = GOBL::Types::Hash[data]
33
+
34
+ new(
35
+ label: data['label'],
36
+ value: data['value']
37
+ )
38
+ end
39
+
40
+ # Returns a hash of GOBL data representing the current object
41
+ #
42
+ # @return [Hash] the array of GOBL data that represents the current object
43
+ def to_gobl
44
+ {
45
+ 'label' => attributes[:label],
46
+ 'value' => attributes[:value]
47
+ }.compact
48
+ end
49
+
50
+ # @!method self.new(attrs)
51
+ #
52
+ # Returns a {ItemCode} object from a given hash of attributes. Nested
53
+ # attributes are supported: the constructor will instantiate the proper GOBL
54
+ # objects when nested hashes or arrays are given as part of the `attrs`
55
+ # parameter.
56
+ #
57
+ # The `new` method will only allow to create a new object if all attributes
58
+ # marked as mandatory and not calculated in the JSON schema are provided.
59
+ #
60
+ # @param attrs [Hash] the hash of attributes
61
+ #
62
+ # @return [ItemCode] the object corresponding to the given input
63
+ end
64
+ end
65
+ end