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,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 Tax
11
+ # RateValue contains a percentage rate or fixed amount for a given date range.
12
+ class RateValue < GOBL::Struct
13
+ # The Schema ID of the GOBL RateValue structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/tax/region#/$defs/RateValue'
15
+
16
+ # @!attribute [r] since
17
+ # Date from which this value should be applied.
18
+ # @return [GOBL::Cal::Date]
19
+ attribute? :since, GOBL::Cal::Date.optional
20
+
21
+ # @!attribute [r] percent
22
+ # Percent rate that should be applied
23
+ # @return [GOBL::Num::Percentage]
24
+ attribute :percent, GOBL::Types.Constructor(GOBL::Num::Percentage)
25
+
26
+ # @!attribute [r] surcharge
27
+ # An additional surcharge to apply.
28
+ # @return [GOBL::Num::Percentage]
29
+ attribute? :surcharge, GOBL::Types.Constructor(GOBL::Num::Percentage).optional
30
+
31
+ # @!attribute [r] disabled
32
+ # When true, this value should no longer be used.
33
+ # @return [Boolean]
34
+ attribute? :disabled, GOBL::Types::Bool.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 [RateValue] the object created from the given data
41
+ def self.from_gobl!(data)
42
+ data = GOBL::Types::Hash[data]
43
+
44
+ new(
45
+ since: data['since'] ? GOBL::Cal::Date.from_gobl!(data['since']) : nil,
46
+ percent: data['percent'],
47
+ surcharge: data['surcharge'] || nil,
48
+ disabled: data['disabled']
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
+ 'since' => attributes[:since]&.to_gobl,
58
+ 'percent' => attributes[:percent]&.to_gobl,
59
+ 'surcharge' => attributes[:surcharge]&.to_gobl,
60
+ 'disabled' => attributes[:disabled]
61
+ }.compact
62
+ end
63
+
64
+ # @!method self.new(attrs)
65
+ #
66
+ # Returns a {RateValue} 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 [RateValue] the object corresponding to the given input
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,100 @@
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 Tax
11
+ # Region defines the holding structure for a regions categories and subsequent Rates and Values.
12
+ class Region < GOBL::Struct
13
+ # The Schema ID of the GOBL Region structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/tax/region'
15
+
16
+ # @!attribute [r] name
17
+ # Name of the region
18
+ # @return [GOBL::I18n::String]
19
+ attribute :name, GOBL::I18n::String
20
+
21
+ # @!attribute [r] country
22
+ # Country code for the region
23
+ # @return [GOBL::L10n::CountryCode]
24
+ attribute :country, GOBL::L10n::CountryCode
25
+
26
+ # @!attribute [r] locality
27
+ # Locality, city, province, county, or similar code inside the country, if needed.
28
+ # @return [GOBL::L10n::Code]
29
+ attribute? :locality, GOBL::L10n::Code.optional
30
+
31
+ # @!attribute [r] localities
32
+ # List of sub-localities inside a region.
33
+ # @return [Localities]
34
+ attribute? :localities, Localities.optional
35
+
36
+ # @!attribute [r] currency
37
+ # Currency used by the region for tax purposes.
38
+ # @return [GOBL::Currency::Code]
39
+ attribute :currency, GOBL::Currency::Code
40
+
41
+ # @!attribute [r] schemes
42
+ # Set of specific scheme definitions inside the region.
43
+ # @return [Schemes]
44
+ attribute? :schemes, Schemes.optional
45
+
46
+ # @!attribute [r] categories
47
+ # List of tax categories.
48
+ # @return [Array<Category>]
49
+ attribute :categories, GOBL::Types::Array.of(Category)
50
+
51
+ # Creates a new object from a hash of GOBL data
52
+ #
53
+ # @param data [Hash] a hash of GOBL data
54
+ #
55
+ # @return [Region] the object created from the given data
56
+ def self.from_gobl!(data)
57
+ data = GOBL::Types::Hash[data]
58
+
59
+ new(
60
+ name: GOBL::I18n::String.from_gobl!(data['name']),
61
+ country: GOBL::L10n::CountryCode.from_gobl!(data['country']),
62
+ locality: data['locality'] ? GOBL::L10n::Code.from_gobl!(data['locality']) : nil,
63
+ localities: data['localities'] ? Localities.from_gobl!(data['localities']) : nil,
64
+ currency: GOBL::Currency::Code.from_gobl!(data['currency']),
65
+ schemes: data['schemes'] ? Schemes.from_gobl!(data['schemes']) : nil,
66
+ categories: data['categories']&.map { |item| Category.from_gobl!(item) }
67
+ )
68
+ end
69
+
70
+ # Returns a hash of GOBL data representing the current object
71
+ #
72
+ # @return [Hash] the array of GOBL data that represents the current object
73
+ def to_gobl
74
+ {
75
+ 'name' => attributes[:name]&.to_gobl,
76
+ 'country' => attributes[:country]&.to_gobl,
77
+ 'locality' => attributes[:locality]&.to_gobl,
78
+ 'localities' => attributes[:localities]&.to_gobl,
79
+ 'currency' => attributes[:currency]&.to_gobl,
80
+ 'schemes' => attributes[:schemes]&.to_gobl,
81
+ 'categories' => attributes[:categories]&.map { |item| item&.to_gobl }
82
+ }.compact
83
+ end
84
+
85
+ # @!method self.new(attrs)
86
+ #
87
+ # Returns a {Region} object from a given hash of attributes. Nested
88
+ # attributes are supported: the constructor will instantiate the proper GOBL
89
+ # objects when nested hashes or arrays are given as part of the `attrs`
90
+ # parameter.
91
+ #
92
+ # The `new` method will only allow to create a new object if all attributes
93
+ # marked as mandatory and not calculated in the JSON schema are provided.
94
+ #
95
+ # @param attrs [Hash] the hash of attributes
96
+ #
97
+ # @return [Region] the object corresponding to the given input
98
+ end
99
+ end
100
+ 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 Tax
11
+ # Scheme contains the definition of a scheme that belongs to a region and can be used to simplify validation processes for document contents.
12
+ class Scheme < GOBL::Struct
13
+ # The Schema ID of the GOBL Scheme structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/tax/region#/$defs/Scheme'
15
+
16
+ # @!attribute [r] key
17
+ # Key used to identify this scheme
18
+ # @return [GOBL::Org::Key]
19
+ attribute :key, GOBL::Org::Key
20
+
21
+ # @!attribute [r] name
22
+ # Name of this scheme.
23
+ # @return [GOBL::I18n::String]
24
+ attribute :name, GOBL::I18n::String
25
+
26
+ # @!attribute [r] description
27
+ # Human details describing what this scheme is used for.
28
+ # @return [GOBL::I18n::String]
29
+ attribute? :description, GOBL::I18n::String.optional
30
+
31
+ # @!attribute [r] categories
32
+ # List of tax category codes that can be used when this scheme is applied.
33
+ # @return [Array<GOBL::Org::Code>]
34
+ attribute? :categories, GOBL::Types::Array.of(GOBL::Org::Code).optional
35
+
36
+ # @!attribute [r] note
37
+ # Note defines a message that should be added to a document when this scheme is used.
38
+ # @return [GOBL::Org::Note]
39
+ attribute? :note, GOBL::Org::Note.optional
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 [Scheme] the object created from the given data
46
+ def self.from_gobl!(data)
47
+ data = GOBL::Types::Hash[data]
48
+
49
+ new(
50
+ key: GOBL::Org::Key.from_gobl!(data['key']),
51
+ name: GOBL::I18n::String.from_gobl!(data['name']),
52
+ description: data['description'] ? GOBL::I18n::String.from_gobl!(data['description']) : nil,
53
+ categories: data['categories']&.map { |item| GOBL::Org::Code.from_gobl!(item) },
54
+ note: data['note'] ? GOBL::Org::Note.from_gobl!(data['note']) : nil
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
+ 'key' => attributes[:key]&.to_gobl,
64
+ 'name' => attributes[:name]&.to_gobl,
65
+ 'description' => attributes[:description]&.to_gobl,
66
+ 'categories' => attributes[:categories]&.map { |item| item&.to_gobl },
67
+ 'note' => attributes[:note]&.to_gobl
68
+ }.compact
69
+ end
70
+
71
+ # @!method self.new(attrs)
72
+ #
73
+ # Returns a {Scheme} 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 [Scheme] the object corresponding to the given input
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,90 @@
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 Tax
11
+ # Schemes defines an array of scheme objects with helper functions.
12
+ class Schemes < GOBL::Struct
13
+ extend Forwardable
14
+ include Enumerable
15
+
16
+ # The Schema ID of the GOBL Schemes structure
17
+ SCHEMA_ID = 'https://gobl.org/draft-0/tax/region#/$defs/Schemes'
18
+
19
+ attribute :_ary, GOBL::Types::Array.of(Scheme)
20
+
21
+ # @!method [](*args)
22
+ # Returns elements from the array
23
+ # @overload [](index)
24
+ # Returns the element in a specific position
25
+ # @param index [Integer] the position of the object
26
+ # @return [Scheme] the element in the `index` position
27
+ # @overload [](start, length)
28
+ # Returns all the elements within a range of positions
29
+ # @param start [Integer] start position of the range
30
+ # @param length [Integer] length of the range
31
+ # @return [Array<Scheme>] the elements in the range
32
+ # @overload [](range)
33
+ # Returns all the elements within a range
34
+ # @param range [Range] start and end positions of the range
35
+ # @return [Array<Scheme>] the elements in the range
36
+ #
37
+ # @!method each
38
+ # Iterates over the array elements
39
+ # @overload each(&block)
40
+ # Calls the given block with each element in the array
41
+ # @yield [element] element of the array
42
+ # @return [self] the object itself
43
+ # @overload each
44
+ # Returns an Enumerator that iterates over the array elements
45
+ # @return [Enumerator] the enumerator of the array elements
46
+ #
47
+ # @!method empty?
48
+ # Returns `true` if the number of elements in the array is zero, `false` otherwise.
49
+ # @return [Boolean] whether the array is empty or not
50
+ #
51
+ # @!method length
52
+ # Returns the number of elements in the array
53
+ # @return [Integer] the number of elements in the array
54
+ def_delegators :_ary, :[], :each, :empty?, :length
55
+
56
+ # Creates a new object from an array of GOBL data
57
+ #
58
+ # @param data [Array] an array of GOBL data
59
+ #
60
+ # @return [Schemes] the object created from the given data
61
+ def self.from_gobl!(data)
62
+ new(_ary: data&.map { |item| Scheme.from_gobl!(item) })
63
+ end
64
+
65
+ # Returns an array of GOBL data representing the current object
66
+ #
67
+ # @return [Array<Hash>] the array of GOBL data that represents the current object
68
+ def to_gobl
69
+ _ary.map(&:to_gobl)
70
+ end
71
+
72
+ # Returns a {Schemes} object from a given array of structs. The array may
73
+ # contain {Scheme} objects or hashes. If hashes are provided, the constructor
74
+ # will call `Scheme#new` to generate the objects that will be part of the
75
+ # returned {Schemes} object
76
+ #
77
+ # @param object [Array<Scheme, Hash>] the array containing the structs
78
+ #
79
+ # @return [Schemes] the object corresponding to the given input
80
+ def self.new(object)
81
+ case object
82
+ when Array
83
+ super _ary: object
84
+ else # internal use, not to be used in public calls
85
+ super
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,90 @@
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 Tax
11
+ # Set defines a list of tax categories and their rates to be used alongside taxable items.
12
+ class Set < GOBL::Struct
13
+ extend Forwardable
14
+ include Enumerable
15
+
16
+ # The Schema ID of the GOBL Set structure
17
+ SCHEMA_ID = 'https://gobl.org/draft-0/tax/set'
18
+
19
+ attribute :_ary, GOBL::Types::Array.of(Combo)
20
+
21
+ # @!method [](*args)
22
+ # Returns elements from the array
23
+ # @overload [](index)
24
+ # Returns the element in a specific position
25
+ # @param index [Integer] the position of the object
26
+ # @return [Combo] the element in the `index` position
27
+ # @overload [](start, length)
28
+ # Returns all the elements within a range of positions
29
+ # @param start [Integer] start position of the range
30
+ # @param length [Integer] length of the range
31
+ # @return [Array<Combo>] the elements in the range
32
+ # @overload [](range)
33
+ # Returns all the elements within a range
34
+ # @param range [Range] start and end positions of the range
35
+ # @return [Array<Combo>] the elements in the range
36
+ #
37
+ # @!method each
38
+ # Iterates over the array elements
39
+ # @overload each(&block)
40
+ # Calls the given block with each element in the array
41
+ # @yield [element] element of the array
42
+ # @return [self] the object itself
43
+ # @overload each
44
+ # Returns an Enumerator that iterates over the array elements
45
+ # @return [Enumerator] the enumerator of the array elements
46
+ #
47
+ # @!method empty?
48
+ # Returns `true` if the number of elements in the array is zero, `false` otherwise.
49
+ # @return [Boolean] whether the array is empty or not
50
+ #
51
+ # @!method length
52
+ # Returns the number of elements in the array
53
+ # @return [Integer] the number of elements in the array
54
+ def_delegators :_ary, :[], :each, :empty?, :length
55
+
56
+ # Creates a new object from an array of GOBL data
57
+ #
58
+ # @param data [Array] an array of GOBL data
59
+ #
60
+ # @return [Set] the object created from the given data
61
+ def self.from_gobl!(data)
62
+ new(_ary: data&.map { |item| Combo.from_gobl!(item) })
63
+ end
64
+
65
+ # Returns an array of GOBL data representing the current object
66
+ #
67
+ # @return [Array<Hash>] the array of GOBL data that represents the current object
68
+ def to_gobl
69
+ _ary.map(&:to_gobl)
70
+ end
71
+
72
+ # Returns a {Set} object from a given array of structs. The array may
73
+ # contain {Combo} objects or hashes. If hashes are provided, the constructor
74
+ # will call `Combo#new` to generate the objects that will be part of the
75
+ # returned {Set} object
76
+ #
77
+ # @param object [Array<Combo, Hash>] the array containing the structs
78
+ #
79
+ # @return [Set] the object corresponding to the given input
80
+ def self.new(object)
81
+ case object
82
+ when Array
83
+ super _ary: object
84
+ else # internal use, not to be used in public calls
85
+ super
86
+ end
87
+ end
88
+ end
89
+ end
90
+ 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 Tax
11
+ # Total contains a set of Category Totals which in turn contain all the accumulated taxes contained in the document.
12
+ class Total < GOBL::Struct
13
+ # The Schema ID of the GOBL Total structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/tax/total'
15
+
16
+ # @!attribute [r] categories
17
+ # Grouping of all the taxes by their category
18
+ # @return [Array<CategoryTotal>]
19
+ attribute? :categories, GOBL::Types::Array.of(CategoryTotal).optional
20
+
21
+ # @!attribute [r] sum
22
+ # Total value of all the taxes applied.
23
+ # @return [GOBL::Num::Amount]
24
+ attribute :sum, GOBL::Types.Constructor(GOBL::Num::Amount)
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 [Total] the object created from the given data
31
+ def self.from_gobl!(data)
32
+ data = GOBL::Types::Hash[data]
33
+
34
+ new(
35
+ categories: data['categories']&.map { |item| CategoryTotal.from_gobl!(item) },
36
+ sum: data['sum']
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
+ 'categories' => attributes[:categories]&.map { |item| item&.to_gobl },
46
+ 'sum' => attributes[:sum]&.to_gobl
47
+ }.compact
48
+ end
49
+
50
+ # @!method self.new(attrs)
51
+ #
52
+ # Returns a {Total} 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 [Total] the object corresponding to the given input
63
+ end
64
+ end
65
+ end
data/lib/gobl/types.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GOBL
4
+ # Types used by the generated GOBL code.
5
+ # @api private
6
+ module Types
7
+ include Dry.Types()
8
+
9
+ Nil = Strict::Nil
10
+ Int = Strict::Integer # deprecated, use Integer
11
+ Integer = Strict::Integer
12
+ Bool = Strict::Bool
13
+ Hash = Strict::Hash
14
+ String = Strict::String
15
+ Double = Strict::Float | Strict::Integer
16
+ end
17
+ 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 UUID
11
+ # Universally Unique Identifier. We only recommend using versions 1 and 4 within GOBL.
12
+ class UUID < GOBL::Struct
13
+ # The Schema ID of the GOBL UUID structure
14
+ SCHEMA_ID = 'https://gobl.org/draft-0/uuid/uuid'
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 [UUID] 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 {UUID} 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 [UUID] the object corresponding to the given value.
41
+ #
42
+ # @example Instantiating from a symbol
43
+ # uuid = GOBL::UUID::UUID.new(:value)
44
+ #
45
+ # @example Instantiating from a string
46
+ # uuid = GOBL::UUID::UUID.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 {UUID} 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 [UUID, 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 {UUID} object
81
+ # uuid = GOBL::UUID::UUID.new('value')
82
+ # uuid == GOBL::UUID::UUID.new('value') #=> true
83
+ # uuid == GOBL::UUID::UUID.new('other') #=> false
84
+ #
85
+ # @example Comparing to a string
86
+ # uuid = GOBL::UUID::UUID.new('value')
87
+ # uuid == 'value' #=> true
88
+ # uuid == 'other' #=> false
89
+ #
90
+ # @example Comparing to a symbol
91
+ # uuid = GOBL::UUID::UUID.new('value')
92
+ # uuid == :value #=> true
93
+ # uuid == :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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GOBL
4
+ VERSION = '0.1.2'
5
+ end
data/lib/gobl.rb ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'zeitwerk'
5
+ require 'dry-struct'
6
+ require 'active_support/core_ext/string/inflections'
7
+ require 'forwardable'
8
+ require 'net/http'
9
+ require 'base64'
10
+
11
+ loader = Zeitwerk::Loader.for_gem
12
+ loader.inflector.inflect(
13
+ 'gobl' => 'GOBL',
14
+ 'gobl_extensions' => 'GOBLExtensions',
15
+ 'uuid' => 'UUID',
16
+ 'url' => 'URL',
17
+ 'item_id' => 'ItemID',
18
+ 'tax_id' => 'TaxID',
19
+ 'dsig' => 'DSig',
20
+ 'id' => 'ID'
21
+ )
22
+ loader.setup
23
+
24
+ # Main GOBL namespace. It provides direct access to the library's configuration (see
25
+ # {Config}) and to the available operations (see {Operations}).
26
+ #
27
+ # The library also provides Ruby classes for each structure defined in the GOBL JSON
28
+ # Schema. They are available in namespaces defined under this one and named after the
29
+ # schema ID of each structure.
30
+ module GOBL
31
+ extend GOBL::Operations
32
+
33
+ # Returns the current configuration of the library
34
+ #
35
+ # @return [GOBL::Config]
36
+ def self.config
37
+ @config ||= Config.new
38
+ end
39
+ end
40
+
41
+ require_relative 'extensions'